delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/01/10/13:45:14

From: "Edd Dawson" <hotcakes AT planetquake DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: stdarg.h problem(s)?
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <%kET9.17088$q67.14211@news-binary.blueyonder.co.uk>
Date: Fri, 10 Jan 2003 18:36:48 -0000
NNTP-Posting-Host: 80.192.26.95
X-Complaints-To: abuse AT blueyonder DOT co DOT uk
X-Trace: news-binary.blueyonder.co.uk 1042223547 80.192.26.95 (Fri, 10 Jan 2003 18:32:27 GMT)
NNTP-Posting-Date: Fri, 10 Jan 2003 18:32:27 GMT
Organization: blueyonder (post doesn't reflect views of blueyonder)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi all,

I am currently running into problems when making functions of an arbitrary
number of arguments in C/C++.
I am using DJGPP version 3.2. Here's a reduced version of the code I'm
trying to work with:

//Code starts here: test.c
#include <stdio.h>
#include <stdarg.h>

void Warning(char *warningstring, ...)
{
   va_list arg_list;
   va_start(arg_list, warningstring);
   printf("WARNING: ");
   printf(warningstring, arg_list);
   va_end(arg_list);
   return;
}


main()
{
   Warning("This is a %s.\n", "test");
}
//Code ends here

Firstly, I'm pretty sure what i've got there is ok and without error -
although I hope someone will prove me wrong in a way... =)
Well, here's what happens....
If use the following command line:

gcc test.c -o test.exe

I get zero compilation errors but this is the output when i run the program:

WARNING: This is a !_.

or something similar. Ok, well that's the first problem. Second one is when
i use this command line instead:

gpp test.c -o test.exe
(gpp rather than gcc)

I get the following compilation errors:

In file included from test.c:2:
c:/djgpp/lib/gcc-lib/djgpp/3.2/include/stdarg.h:110: conflicting types for `
    typedef char*va_list'
c:/djgpp/include/stdio.h:35: previous declaration as `typedef void*va_list'

So then I tried renaming c:/djgpp/lib/gcc-lib/djgpp/3.2/include/stdarg.h to
something else for the time being. It then compiled fine, but then same
thing happened when executing the program i.e. incorrect output.
Incidentally, I have also tried doing Warning("number is %d\n", 123456); and
it's given me an output of something like 1212356, which is also clearly
wrong.

Can anyone help?

Edd


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019