question about wmp_load.c example in wmpmdlSDK

Posted By: LazyDog

question about wmp_load.c example in wmpmdlSDK - 01/18/09 23:14

in the load_block function, the following code:

if ( wmpTexture->tex_flags)
{
printf("texture_flags: %d,%d\n", wmpTexture->tex_flags);
}

how does this output 2 values when you are only providing one variable which is tex_flags?
Posted By: jcl

Re: question about wmp_load.c example in wmpmdlSDK - 01/19/09 07:27

That's apparently a bug - please remove the superflous "%d" from printf.
Posted By: LazyDog

Re: question about wmp_load.c example in wmpmdlSDK - 01/19/09 13:46

Actually, your binary version of wmp_load.exe in the samples directly does write 2 values out. when I ran it against a small test level it reported 8192,7
Posted By: jcl

Re: question about wmp_load.c example in wmpmdlSDK - 01/19/09 15:20

Sure, printf prints 2 values because it was told so. In our programmer job interviews, one of the questions is:

What happens when you have the line

printf("%d");

in your C/C++ code? Will it a) give a compiler error, b) crash, or c) print a value - and if so, which one?

When you can answer this question in a job interview, you have a chance to get hired by Conitec.
Posted By: LazyDog

Re: question about wmp_load.c example in wmpmdlSDK - 01/19/09 19:04

the answer is c) and the value is undefined-- it depends on what is in memory for that variable at that time.

so am I'm hired?

I just wanted to make sure that instead of removing the second %d that perhaps the problem was that the author of wmp_load.c (if that was not you) simply forgot to actually add the second variable. I now realize that indeed, the second %d was not meant to be there and it should be removed.

thanks
Posted By: jcl

Re: question about wmp_load.c example in wmpmdlSDK - 01/20/09 08:37

You'd be almost hired. The value is not undefined - it's the last local variable of the printf calling function. That's because functions take their parameters from the stack and local variables are also stored there. You can safely remove the second "%d".
© 2023 lite-C Forums