A TINY BUG

Charles Curley ccurley@wyoming.com
Mon Oct 6 15:47:00 GMT 1997


At 12:38 AM 10/6/97 +0000, Tage Westlund wrote:
>To gnu designers!
>I have found that the following bad code gives "exception" at run
>time instead of error message at compilation time (b18 Win95):
>
>#include <stdio.h>
>main(){
>	printf("%s\n",sizeof(long));
>}
>Tage

That does not surprise me in the least. A lot of compilers do no type
checking for printf.

Here's the results on Microsoft C++ 4.0:

cd ~/
cl test.c
Microsoft (R) 32-bit C/C++ Standard Compiler Version 10.00.6002 for 80x86
Copyright (C) Microsoft Corp 1984-1996. All rights reserved.

test.c
Microsoft (R) 32-Bit Incremental Linker Version 3.00.5270
Copyright (C) Microsoft Corp 1992-1995. All rights reserved.

/out:test.exe 
test.obj 

Compilation finished at Mon Oct 06 16:32:37


Here's what I got for Microsoft C++ 5.0:



--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.c
C:\Crc\test.c(4) : warning C4035: 'main' : no return value

test.obj - 0 error(s), 1 warning(s)



Nice of them to warn us about the lack of return value :-)

What happened is this: printf (and its relatives) is a library function
which takes an indeterminate number of arguments, of indeterminate data
type. The compiler and linker cannot scan the inputs for correct typing.

Why, you ask, can't the compiler "know" what printf *should* take, and scan
and test accordingly? The answer is that some programs provide their own
printfs, and some developers don't use the library printf, and there is no
way the compiler writers can anticiapte the syntaxes of those versions.

Now, even though it is not a gcc - specific question, would the Keeper of
the FAQ please add this or something like it?


		-- C^2

Looking for fine software and/or web pages?
http://web.idirect.com/~ccurley
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list