Bug 38104 - gcc fails to compile programs if va_arg macro is used with types other than int
gcc fails to compile programs if va_arg macro is used with types other than int
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-04-27 15:13 EDT by Michael McTernan
Modified: 2007-04-18 12:32 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-04-27 15:13:49 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Michael McTernan 2001-04-27 15:13:44 EDT
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 19:41:33 EDT
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.