Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* stdarg's unpredictable
@ 1994-01-14 22:40 anh
  1994-01-15 19:58 ` Daniel S. Riley
  1994-01-17 22:19 ` Gerald Feldman USG
  0 siblings, 2 replies; 3+ messages in thread
From: anh @ 1994-01-14 22:40 UTC (permalink / raw)



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 <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdarg.h>

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);
}



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1994-01-17 22:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-01-14 22:40 stdarg's unpredictable anh
1994-01-15 19:58 ` Daniel S. Riley
1994-01-17 22:19 ` Gerald Feldman USG

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox