where is stdarg.h of gcc

M

mobile.parmenides

Hi all, This is a fragment of code to test how stdarg.h to works. It's
ok when compiling with lcc. But, compiling it with gcc, some trouble
arise like these:

gcc: 2: No such file or directory
va.c: In function ‘main’:
va.c:10: error: expected expression before ‘int’

My source code is as follows:


#include <stdio.h>
#include <stdarg.h>

void arg_test(int i, ...);

int main(int argc,char *argv[])
{

int int_size = _INTSIZEOF(int *);
printf("int_size=%d\n", int_size);
arg_test(0, 4);

arg_test(4,1,2,3,4);
return 0;
}

void arg_test(int i, ...)
{
int j=0;
va_list arg_ptr;

va_start(arg_ptr, i);
printf("&i = %p\n", &i);
printf("arg_ptr = %p\n", arg_ptr);

j=*((int *)arg_ptr);
printf("%d %d\n", i, j);
j=va_arg(arg_ptr, int);
printf("arg_ptr = %p\n", arg_ptr);
va_end(arg_ptr);
printf("%d %d\n", i, j);
}
 
T

Tomás Ó hÉilidhe

     int int_size = _INTSIZEOF(int *);


What's "_INTSIZEOF"? It's not a part of any of the C standards.

As for finding a file, well under Linux:

find / -name stdarg.h

Under MS Windows:

cd\
dir/a/s stdarg.h
 
M

Martin Ambuhl

Hi all, This is a fragment of code to test how stdarg.h to works. It's
ok when compiling with lcc. But, compiling it with gcc, some trouble
arise like these:

It should work fine with gcc (and does, once I cleaned up the
non-standard _INTSIZEOF and the arguments for printf.

You almost certainly have made some error in installing gcc or your
libraries, if supplied separately. I suggest you check your
documentation.
 
K

Keith Thompson

Hi all, This is a fragment of code to test how stdarg.h to works. It's
ok when compiling with lcc. But, compiling it with gcc, some trouble
arise like these:

gcc: 2: No such file or directory

If gcc gave you this message, then it's looking for a file named "2",
presumably because you told it to.
va.c: In function `main’:
va.c:10: error: expected expression before `int’

(I've changed the left single quotation marks to ASCII backticks.)
My source code is as follows:


#include <stdio.h>
#include <stdarg.h>

void arg_test(int i, ...);

int main(int argc,char *argv[])
{

int int_size = _INTSIZEOF(int *);

As others have pointed out, _INTSIZEOF is non-standard. Does "sizeof"
not suit your purpose here?

[...]
void arg_test(int i, ...)
{
int j=0;
va_list arg_ptr;

va_start(arg_ptr, i);
printf("&i = %p\n", &i);

"%p" expects an argument of type void*; &i is of type int*. This is
likely to work on many implementations, but to be safe you should
convert it explicitly:

printf("&i = %p\n", (void*)&i);
printf("arg_ptr = %p\n", arg_ptr);

arg_ptr is of type va_list. The standard says only that va_list is an
object type; it needn't be a pointer type. There's no portable way to
print a va_list value, unless you treat it as an array of unsigned
char.

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top