Lets say in a file I have some code in two files part of the same project
file1.c
int func1(int a, int b, int c, bool d)
{
/* function body */
}
file2.c
extern func1(int a, int b, int c);
/* function call */
func1(runtime1, runtime2, runtime3);
What would be value bool d
takes when being called from file2.c? I know this is really bad practice, but I am maintaining old code and somebody did this, I just want to know the default parameter or if it is implementation dependent. Please note also, that bool
in this example is a typedef of the software, since this specific project does not support C99. Thank you.!
The value would be undefined. When calling func1, its parameters go on the stack. If you call it with 1 parameter less, the stack will be sizeof(bool)
bytes short of what the process expects. This will not crash your program as your stack and your heap are "facing", but if you try to access to d
, you will access to whatever value is there on the stack -> rubbish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With