Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: anh@kuhub.cc.ukans.edu
Subject: stdarg's unpredictable
Date: 14 Jan 94 16:40:03 CST	[thread overview]
Message-ID: <1994Jan14.164003.57216@kuhub.cc.ukans.edu> (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);
}



             reply	other threads:[~1994-01-14 22:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-01-14 22:40 anh [this message]
1994-01-15 19:58 ` stdarg's unpredictable Daniel S. Riley
1994-01-17 22:19 ` Gerald Feldman USG
read-only archive

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