From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,daa9a948bbcdbea6,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-01-14 19:45:12 PST Path: gmd.de!xlink.net!howland.reston.ans.net!vixen.cso.uiuc.edu!uwm.edu!caen!kuhub.cc.ukans.edu!anh From: anh@kuhub.cc.ukans.edu Newsgroups: comp.unix.osf.osf1 Subject: stdarg's unpredictable Message-ID: <1994Jan14.164003.57216@kuhub.cc.ukans.edu> Date: 14 Jan 94 16:40:03 CST Organization: University of Kansas Academic Computing Services Hello everybody, I compiled the below program on a Dec 3000/500 AXP ALPHA running OSF/1. To compile and to run: cc test.c then a.out :-). Anyway, the point is, if I uncomment the commented printf line, I will get a different results. No, not test: Hello World showing up and not showing up.:-). I used to get segmented fault without the printf and strange output with printf. After changing the string in the test() call, A space more or less, I don't remember. I no longer get segmented fault, but the program is still not functioning correctly. The output and the behavior is unpredictable. Can someone shed some light? Change test(" .... ...") to include more parameters, a space more or less. Comment and uncomment the printf in test(), and you'll see what I mean. I put this test program together because we experience some strange behavior in one of our other monitoring program. I tracked the problem to the functions using arbitrary number of arguments. Thanks for all help. Anh #include #include #include #include void test(format) char *format; { va_list vlist; char msg[500]; va_start(vlist,format); vsprintf(msg,format,vlist); va_end(vlist); /* printf("\n\ntest: %s\n",msg);*/ } main() { unsigned int a=4; unsigned long b=4; char name[]="Hello World"; printf("sizeof(size_t)=%d sizeof(u int)=%d, sizeof(int)=%d, sizeof(u_long)=%d, sizeof(long)=%d\n", sizeof(size_t),sizeof(unsigned int),sizeof(int),sizeof(u_long),sizeof(long)); printf("a=%d, b=%d\n",a,b); printf("ntohl(a)=%u, htonl(a)=%u, ntohl(htonl(a))=%u\n",ntohl(a),htonl(a), ntohl(htonl(a))); printf("ntohl(b)=%lu, htonl(b)=%lu, ntohl(hotnl(b))=%lu\n",ntohl(b),htonl(b), ntohl(htonl(b))); printf("\n%s\n",name); test("ntohl(b)=%d, htonl(b)=%d, %s\n",ntohl(b),htonl(b),name); }