Bug 38104 - gcc fails to compile programs if va_arg macro is used with types other than int
Summary: gcc fails to compile programs if va_arg macro is used with types other than int
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-04-27 19:13 UTC by Michael McTernan
Modified: 2007-04-18 16:32 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-04-27 19:13:49 UTC
Embargoed:


Attachments (Terms of Use)

Description Michael McTernan 2001-04-27 19:13:44 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.2-2 i686)


[mm7323@mike bug]$ cat bug.c 
#include <stdarg.h>
#include <stdio.h>

typedef unsigned short  myType;

void func(int n,...) {
 va_list ap;
 myType b;

 va_start(ap,n);
 b=va_arg(ap,myType);
 va_end(ap);
 
 printf("%d\n",b); 
}

int main(int argC,char *argV[]) {
  func(1,12345);
  return 0;
}
[mm7323@mike bug]$ gcc bug.c
bug.c: In function `func':
bug.c:11: `myType' is promoted to `int' when passed through `...'
bug.c:11: (so you should pass `int' not `myType' to `va_arg')
[mm7323@mike bug]$ 


Reproducible: Always
Steps to Reproduce:
1. Attempt to compile the test program given in the description
2.
3.
	

Actual Results:  bug.c: In function `func':
bug.c:11: `myType' is promoted to `int' when passed through `...'
bug.c:11: (so you should pass `int' not `myType' to `va_arg')

Expected Results:  It should just compile making a.out.  I understood that
anything can be passed to va_arg, not just ints. 

This prevents some software from being compiled e.g. lib icq...

Comment 1 Jakub Jelinek 2001-04-27 23:41:33 UTC
C promotes char and short to int when passing to ... arguments. The compiler
is right to make it obvious this is a bug. A varargs function will simply
never get a char or short as vararg, therefore if you want to pass a short
through varargs, you should use (myType)va_arg(ap, int).
Similarly with float (which is promoted to double).
If there are programs which don't do this, they should be fixed.


Note You need to log in before you can comment on or make changes to this bug.