A
Alex Vinokur
------ foo.c ------
void func() {}
int main()
{
func (100, 200, 300);
return 0;
}
void func() {}
int main()
{
func (100, 200, 300);
return 0;
}
------ foo.c ------
void func() {}
int main()
{
func (100, 200, 300);
return 0;
}
Richard Heathfield said:Alex Vinokur said:
It can't use the arguments, because it doesn't take any parameters.
But that program is valid C-program.
Why does C allow that?
Alex Vinokur said:[...]void func() {}
How can func() use its arguments 100, 200, 300?
It can't use the arguments, because it doesn't take any parameters.
Richard Heathfield skrev:Alex Vinokur said:[...]void func() {}
How can func() use its arguments 100, 200, 300?
It can't use the arguments, because it doesn't take any parameters.
Way too easy for R.H., now can he explain this:
(*(void(*)())0)();
Tor Rustad said:
[...]
Way too easy for R.H., now can he explain this:
(*(void(*)())0)();
Sure. It's line noise. Or, if you prefer, undefined behaviour.
Std quotes are from n1124:
6.3.2.3 Pointers:
"An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer constant.
If a null pointer constant is converted to a pointer type, the
resulting pointer, called a null pointer, is guaranteed to compare
unequal to a pointer to any object or function."
Therefore, (void(*)())0 does not point to a function, and
yet has function pointer type.
Thus, (*(void(*)())0)() is attempting to call a function that does not exist.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.