delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/01/11/06:00:12

From: "Ben Peddell" <killer DOT lightspeed AT bigpond DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <%kET9.17088$q67 DOT 14211 AT news-binary DOT blueyonder DOT co DOT uk>
Subject: Re: stdarg.h problem(s)?
Lines: 148
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Message-ID: <dxST9.21164$jM5.58362@newsfeeds.bigpond.com>
Date: Sat, 11 Jan 2003 20:52:04 +1000
NNTP-Posting-Host: 144.139.175.57
X-Trace: newsfeeds.bigpond.com 1042281673 144.139.175.57 (Sat, 11 Jan 2003 21:41:13 EST)
NNTP-Posting-Date: Sat, 11 Jan 2003 21:41:13 EST
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

To remove the compilation errors, either delete stdarg.h in the
lib/gcc-lib/djgpp/3.21/include directory, or move it elsewhere.
Here's what your code should be:

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

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

int main(void)
{
    Warning("This is a %s.\n","test");
}
file://test.c ends here

Here's the output:

Microsoft(R) Windows 98
   (C)Copyright Microsoft Corp 1981-1999.

E:\DJGPP>gcc -o test2 test2.c

E:\DJGPP>test2
WARNING: This is a test.

E:\DJGPP>exit


Here's the output with Warning("This is a %s.\n","test"); changed to
Warning("number is %d.\n",123456);

Microsoft(R) Windows 98
   (C)Copyright Microsoft Corp 1981-1999.

E:\DJGPP>gcc -o test2 test2.c

E:\DJGPP>test2
WARNING: number is 123456.

E:\DJGPP>exit







Edd Dawson <hotcakes AT planetquake DOT com> wrote in message
news:%kET9.17088$q67 DOT 14211 AT news-binary DOT blueyonder DOT co DOT uk...
> 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:
>
> file://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);

libc.inf says that, for what you are wanting to do, you should use vprintf.

>    va_end(arg_list);
>    return;
> }
>
>
> main()
> {
>    Warning("This is a %s.\n", "test");
> }
> file://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

When I do the same, I get the following:
|    E:\DJGPP>gcc test2.c -o test2.exe
|    In file included from test2.c:2:
|    e:/djgpp/lib/gcc-lib/djgpp/3.21/include/stdarg.h:110: conflicting types
for `va_list'
|    e:/djgpp/include/stdio.h:35: previous declaration of `va_list'
and I get no object output at all.

Moving all of the .h files from the lib/gcc-lib/djgpp/3.21/include directory
into a backup sub-directory fixed this, as it seems that this directory is
seen before the proper include directory.

>
> 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