More fun and games with gcc, A/UX, and porting MPW code.

David J Peterson djp862 at anu.oz.au
Wed Jun 12 18:35:39 AEST 1991


Hello all,

Thanks to all who repsonded on the variable argument problem, I got
that sorted out. Now here's a new one for you.

Is there some reason why I can only pass 4 byte quantities between
function using gcc (v1.39) when I use function prototypes, but can pass
anything I want when I don't use prototypes?

Take a look at the following if that didn't make sense, its a simple
program and the output, or errors from gcc.

--------------------------
#include <stdio.h>

#ifdef PROTO
void printtest(long, int, short, char, char *);
#else
void printtest();
#endif

void main()
{
	long	l	= 4000000000;
	int	i	= 4000000000;
	short	s	= 65000;
	char	c	= 'C';
	char	*cp	= "StringPtr";
	
	printtest(l, i, s, c, cp);
}

void printtest(l, i, s, c, cp)
	long	l;
	int	i;
	short	s;
	char	c;
	char	*cp;
{
	printf("long\t%d\tsize: %d\n", l, sizeof(l));
	printf("int\t%d\tsize: %d\n", i, sizeof(i));
	printf("short\t%d\t\tsize: %d\n", s, sizeof(s));
	printf("char\t%c\t\tsize: %d\n", c, sizeof(c));
	printf("char *\t%s\tsize: %d\n", cp, sizeof(cp));
}
------------------

and then:

------------------
% gcc -o test test.c
% ./test
long    -294967296      size: 4
int     -294967296      size: 4
short   -536            size: 2
char    C               size: 1
char *  StringPtr       size: 4
% gcc -DPROTO -o test test.c
test.c
test.c: In function printtest:
test.c:26: argument `s' doesn't match function prototype
test.c:26: a formal parameter type that promotes to `int'
test.c:26: can match only `int' in the prototype
test.c:26: argument `c' doesn't match function prototype
test.c:26: a formal parameter type that promotes to `int'
test.c:26: can match only `int' in the prototype
%
------------------

Whats the deal here? The '-traditional' and/or '-ansi' flags in gcc
don't make any difference. And the native cc doesn't deal with
prototypes at all.

-dave.



More information about the Comp.unix.aux mailing list