473,799 Members | 3,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange va_list problem

Reading the standard, va_list is an object type (, so I believe the
following should be possible:

#include <stdarg.h>

void foo(va_list *arg)
{
/* do some stuff which conditionally might read parameters off arg */
}

void bar(va_list arg)
{
foo(&arg);
}

Yet when I compile this on a powerpc linux box with gcc I get the following:
markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
t.c:3: warning: unused parameter 'arg'
t.c: In function `bar':
t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type

I don't care about the unused argument warning since obviously the real
code is rather more complex and uses it, it is the incompatible pointer
type warning I believe is wrong.

Am I correct in thinking this should work?

The real code is something like a printf function and foo is a function
for handling a format specifier where it conditionally wants to pull
further arguments off the argument list. Any good alternative solutions
to this problem will be welcome.

This is not my code, but I'm maintaining it and life would be easier for
me if it built cleanly on my powerpc Linux box. It builds cleanly with
gcc on x86.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #1
7 2864
As my understanding, the type of va_list should be "char*", I think
you might use it as the type of "char*" as where you use it, it is just
a pointer in 4 bytes when it's compiled.

May 10 '06 #2
ca*******@gmail .com wrote:
As my understanding, the type of va_list should be "char*",
Even without any context (a pox on Google Groups!), your understanding
is wrong...
I think you might use it as the type of "char*" as where you use it,
it is just a pointer in 4 bytes when it's compiled.


....as is your assumption about the size of either va_list or char *.

Richard
May 10 '06 #3
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Reading the standard, va_list is an object type (, so I believe the
following should be possible:

#include <stdarg.h>

void foo(va_list *arg)
{
/* do some stuff which conditionally might read parameters off arg */
}

void bar(va_list arg)
{
foo(&arg);
}

Yet when I compile this on a powerpc linux box with gcc I get the following:
markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
t.c:3: warning: unused parameter 'arg'
t.c: In function `bar':
t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type


AFAICT your belief is correct, and gcc is wrong.

Richard
May 10 '06 #4
In article <c4************ @news.flash-gordon.me.uk> Flash Gordon <sp**@flash-gordon.me.uk> writes:
....
void bar(va_list arg)
{
foo(&arg);
}

Yet when I compile this on a powerpc linux box with gcc I get the following:
markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
t.c:3: warning: unused parameter 'arg'
t.c: In function `bar':
t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type


Which version of gcc? I do not get the warning in either gcc 2.95.2 or
gcc 4.0.2.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
May 10 '06 #5
Flash Gordon wrote:
Reading the standard, va_list is an object type (, so I believe the
following should be possible:

#include <stdarg.h>

void foo(va_list *arg)
{
/* do some stuff which conditionally might read parameters off arg */
}

void bar(va_list arg)
{
foo(&arg);
}

Yet when I compile this on a powerpc linux box with gcc I get the following:
markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
t.c:3: warning: unused parameter 'arg'
t.c: In function `bar':
t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type


Looks like a problem with the compiler to me (which honestly wouldn't
be a surprise to me in this case), what build of gcc are you using?

Robert Gamble

May 10 '06 #6
Dik T. Winter wrote:
In article <c4************ @news.flash-gordon.me.uk> Flash Gordon <sp**@flash-gordon.me.uk> writes:
...
> void bar(va_list arg)
> {
> foo(&arg);
> }
>
> Yet when I compile this on a powerpc linux box with gcc I get the following:
> markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
> t.c:3: warning: unused parameter 'arg'
> t.c: In function `bar':
> t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type


Which version of gcc? I do not get the warning in either gcc 2.95.2 or
gcc 4.0.2.


$ gcc -v
Reading specs from /usr/lib/gcc/powerpc-unknown-linux-gnu/3.4.5/specs
Configured with: /var/tmp/portage/gcc-3.4.5-r1/work/gcc-3.4.5/configure
--prefix=/usr --bindir=/usr/powerpc-unknown-linux-gnu/gcc-bin/3.4.5
--includedir=/usr/lib/gcc/powerpc-unknown-linux-gnu/3.4.5/include
--datadir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/3.4.5
--mandir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/3.4.5/man
--infodir=/usr/share/gcc-data/powerpc-unknown-linux-gnu/3.4.5/info
--with-gxx-include-dir=/usr/lib/gcc/powerpc-unknown-linux-gnu/3.4.5/include/g++-v3
--host=powerpc-unknown-linux-gnu --build=powerpc-unknown-linux-gnu
--disable-altivec --enable-nls --without-included-gettext
--with-system-zlib --disable-checking --disable-werror
--disable-libunwind-exceptions --disable-multilib
--enable-languages=c,c++ ,java,f77 --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)

Note that this is running on a iMac, so it is ppc rather than x86. They
may be doing things differently.

Sounds like it might be worth raising a bug report on it.

Thanks Dik, also thanks to Richard Bos.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #7
Richard Bos wrote:
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Reading the standard, va_list is an object type (, so I believe the
following should be possible:

#include <stdarg.h>

void foo(va_list *arg)
{
/* do some stuff which conditionally might read parameters off arg */
}

void bar(va_list arg)
{
foo(&arg);
}

Yet when I compile this on a powerpc linux box with gcc I get the following:
markg@home ~/work/ffdev $ gcc -ansi -pedantic -Wall -W -O -c t.c
t.c:3: warning: unused parameter 'arg'
t.c: In function `bar':
t.c:9: warning: passing arg 1 of `foo' from incompatible pointer type


AFAICT your belief is correct, and gcc is wrong.


It seems that the bugzilla search engine is not very good. Using va_list
as a search term did not find the relevant bug, which is
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557
Someone else did and marked my bug as a duplicate. Others have been
caught by this as well!

Apparently, on some implementations (including mine) va_list is
implemented as an array. Let's say the definition of va_list is:
typedef __va_type va_list[10];

Since arrays are not really passed, only a pointer to the first element,
this makes my code equivalent to:
#include <stdarg.h>

void foo(va_list *arg)
{
/* do some stuff which conditionally might read parameters off arg */
}

void bar(__va_type *arg)
{
foo(&arg);
}

So I'm passing a pointer to pointer to __va_type instead of a pointer to
array[10] of __va_type.

A subtle problem, but I can see that an array is an object type so the
gcc implementation is valid. A shame that __builtin_va_li st is
implemented as a magic type so I could not see it was an array.

I should now be able to fix this code.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3695
by: Peter | last post by:
-------------------------------------------------------------------------------- Hi, I was wondering if we can create a va_list by adding objects in the va_list instead of passing in the parameter preceding first optional argument? In another words, I want to create a va_list in a similar manner as creating an array. The reason is I want to use FormatMessage() in my program where it
3
16782
by: Douwe | last post by:
I try to build my own version of printf which just passes all arguments to the original printf. As long as I keep it with the single argument version everything is fine. But their is also a version which uses the "..." as the last parameter how can I pass them to the orignal printf ? void myprintf(char *txt, ...) printf(txt, ???????); }
2
3346
by: Joerg Schoen | last post by:
Hi folks! I have a function that gets a 'va_list'. I am passing the 'va_list' two times to a function like 'vprintf' to print it out. I thought that this was portable until I came across a platform (AS/400) where it fails: The 'va_list' is actually defined as some some kind of an array, so passing it happens by *reference*: The first user will destroy it and the second
11
3076
by: thierrydollar | last post by:
Hi, I have written a very simple program using variable arguments calls and I get strange things that I cannot explain. I have one function (add) that displays two parameters. It works well when I call it directly. Now I have a second function (set) that also calls add. But this doesn't
1
9476
by: skillzero | last post by:
Is there a portable way to pass a va_list as a parameter to another function taking a variable argument list? I have a function that takes a printf-like format string and I'd like to use something like %V to pass in another format string and a va_list to allow nesting. It happens to work on my compiler, but I wasn't sure if it's portable to use va_list's as parameters to a variable argument function because va_list isn't always just a...
4
19250
by: Tor Rustad | last post by:
I have a C program, where I control the error behavior according to context: /* some error handlers */ static void on_error_log (MYSQL *mysql, const char *msg, ...); .... static void on_error_exit (MYSQL *mysql, const char *msg, ...); /* the error function */ static void (*error_fatal) (MYSQL *mysql, const char *msg, ...) =
6
11683
by: ramu | last post by:
Hi, Can we intialize va_list to NULL? ie. va_list = NULL Regards
8
2777
by: Fred | last post by:
I've got following program encapsuled fscanf, however, it doesn't work. I'm sure that the content format in "a.txt" is OK, the content would be correctly read if using fscanf directly, what's wrong with my program? Thanks for help! int vsscanf( FILE* fp, const char *fmt, ... ) { va_list arglist; va_start( arglist, fmt );
1
5551
by: Chuck Chopp | last post by:
I have some code that is being built on the following: Windows Server 2003, both 32-bit & 64-bit editions Windows Vista, both 32-bit & 64-bit editions Windows Server 2008, both 32-bit & 64-bit editions Build tools: Visual Studio 2008. SLES 10 SP1, both 32-bit & 64 bit editions
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.