General discussion


Any thoughts on this?

By stargazerr ·
void main(void)
int i=10;

printf("i = %d",i);

void func(void)
/* Your code goes here, change i to 100 */

// No global declarations allowed, you are allowed to add ur code only in the space provided

I was thinking about declaring another local variable and prontf and exit the program, but obviously, thats too easy.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

bad sg, bad sg, void func should never be used

by Jaqui In reply to Any thoughts on this?

int main(argc, argv)
int i=10;

printf("i = %d",i);
return 0;

int func(i)
return i;

edited for formatting

Collapse -

My C is a bit rusted

by stargazerr In reply to bad sg, bad sg, void func ...

but how can you use an argument in the function if none has been specified?


Collapse -

so I missed the i in calling func()..

by Jaqui In reply to My C is a bit rusted

main always has argc and argv available.

and void main is a fatal error now, has been for a few years.

the idea being that exit codes [ the return ] will help track app crashes.

Collapse -

help track app crashes

by rob mekel In reply to so I missed the i in call ...

and that is done to little now a day's building in exit codes to help with tracking. On the other hand it slows down the app's so it's a matter of opinion what is best.

Or is my C to rusty now.


Collapse -


by Jaqui In reply to help track app crashes

it does slow an app down slightly.
but error handling is usually really only included until after the beta cycle. It should be a part of the app forever, but they remove it from stable releases for the speed.
checking every function for errors is supposed to be done, but often gets ignored.

Collapse -


by rob mekel In reply to yup

so it comes down on the testing and final release, but heck, if you change after final testing ... where did that bug come from ... and testing even the final release.

Well it's all human so failures are inevitable.


Collapse -

I agree,

by Jaqui In reply to right

but then I'm nuts and leave usefull error codes in the returns even on a release application.
makes it a lot easier to solve the inevitable bugs that show up in use.

I got really frustrated installing a Borland Product [ Kylix 3 ] with their generic error code 10 message. took me six months to figure out they built the damned app against a specific toolchain, so installing onto newer version of the os killed the app.
So now I have a commercial ide for linux that requires a 1990 version of linux.

Collapse -

Has it?

by stargazerr In reply to so I missed the i in call ...

I used void main till last year.

And i cant change any arguments in this program. Cannot add any arguments to the calling function, which is the usual way to go. Everything has to be local to the function func()


Collapse -

then use

by Jaqui In reply to Has it?

a pointer.

*i is a reference to the location of i.
i is declared in main, so it's a local variable.
the pointer may not work...

nope, it doesn't.

Collapse -

thats the point

by stargazerr In reply to then use

I cant use anything. the only code i can put in is local to func() and pointers wont help ..

Related Discussions

Related Forums