serious: GCC 2.95.3 accepts illegal function call

Daniel Berlin dan@cgsoftware.com
Fri Sep 7 11:32:00 GMT 2001


Michael Noisternig <michael.noisternig@sbg.ac.at> writes:

> Check this:
>
> --- begin code ---
>
> typedef long long uint64;
>
> uint64 calculate_cpu_timing_factors (unsigned int instr)
> {
> 	// ...
> }
>
> uint64 calculate_cpu_timing()
> {
> 	return calculate_cpu_timing(calculate_cpu_timing(10000)/1024);
> }
>
> --- end code ---
>
> This piece of code is happily accepted by the compiler! Check it 'til
> you find the error, it took me the whole day :-(((
For starters, you have long long, rather than unsigned long long,
typedef'd to uint64.

Second, if you say "uint64 calculate_cpu_timing(void)" instead of
"uint64 calculate_cpu_timing", you'd get:

testul.c: In function `calculate_cpu_timing':
testul.c:8: too many arguments to function `calculate_cpu_timing'
testul.c:8: too many arguments to function `calculate_cpu_timing'

Third, if you really intend to call calculate_cpu_timing_factors with
those arguments, then you should probably make the argument to it a
uint64.
Unless you have a guarantee that the uint64 it returns, divided by
1024, will now be in the range of unsigned int.

>
> Michael Noisternig.

-- 
"I just got out of the hospital.  I was in a speed reading
accident.  I hit a book mark and flew across the room.
"-Steven Wright



More information about the Gcc-bugs mailing list