From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,4792fab2c528013d X-Google-Attributes: gid111c93,public From: "Martin Sinot" Subject: Re: Oddities... Date: 1999/11/10 Message-ID: <80bll5$nse$1@news.telekabel.nl>#1/1 X-Deja-AN: 546854794 References: X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Trace: news.telekabel.nl 942234085 24462 212.142.20.102 (10 Nov 1999 11:41:25 GMT) Organization: SPaSE BV NNTP-Posting-Date: 10 Nov 1999 11:41:25 GMT Newsgroups: comp.os.linux.alpha John wrote in message news:MPG.1292ced3190663a5989695@oh.news.verio.net... > I was helping a friend on his intro to c course and I got > curious as to what it would do on my alpha. Why does this > code.. give unaligned traps, on argv[0-2]?? > > #include // Standard Sheeet. > // World Domination?? FREE WODKA!! > int I;// one lame var.. > > main(int argc, int *argv[]) > { > if(argc==0){ > printf("Usage: %s values\n", argv[1]); > return(1); > } > for(I=0; I printf(" argv[%d]: %s\n\n", I, argv[I]); > } > printf("The following are the results.\n"); > for(I=0; I if(*argv[I]>101) > [...else if's down to zero...] Hmm, this is actually a C question, which should go to another newsgroup. Your problem will occur on every system that has alignment traps (including Alphas). The problem is in the prototype of main. The correct prototype is: int main (int argc, char *argv[]) (note char* instead of int*). The argv argument points to a list of char pointers, which represent the arguments passed to the program, as zero terminated strings. The list is terminated with a null pointer. Now these arguments are usually simply concatenated in memory, with null bytes between them to separate them. That means that these pointers may or may not be aligned (probably not...). Now more downward you try to deference such a pointer as a pointer to an int, which means that an int is being read from a nonaligned address -- boom. >From the above program fragment I understand that you want to pass some numbers to the program as parameters. Parameters are always passed as strings. If you want numbers instead, you will have to convert them yourself. One small thing: the first "parameter" passed to the program is always the program name, and this is also counted in argc. Martin Sinot martin@spase.nl