hi, int main(void) { main(); return 0; } wat does the standard says about the above code snippet?
hi, int main(void) { main(); return 0; } wat does the standard says about the above code snippet?
Nothing, This will result in infinite loop. Eating a lot of processor time, and you may see your PC hang. Thanks.
XXXX@XXXXX.COM writes: It's a recursive call to main, which is perfectly legal. Like any infinite recursive call, it will either exceed some system resource limit, or it will run indefinitely (if the compiler optimizes tail recursion). The "return 0;" will never be reached. -- Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.**--****.com/ ~kst> San Diego Supercomputer Center <*> < http://www.**--****.com/ ~kst> We must do something. This is something. Therefore, we must do this.
Wrong, the standard says what will happen if you call main recursively. Or the compiler could fail to optimise it in which case the loop will not be infinite since you will run out of stack space. Or process limits might prevent it from eating a log of CPU time. Or the compiler might optimise it to some form of sleep forever instruction. Please provide context when replying, Google is *not* Usenet. See the Google section at http://www.**--****.com/ links to. -- Flash Gordon, living in interesting times. Web site - http://www.**--****.com/ comp.lang.c posting guidelines and intro: http://www.**--****.com/ Inviato da X-Privat.Org - Registrazione gratuita http://www.**--****.com/
It may run forever, or crash. I don't know if a stack overflow (i.e. running out of memory in a way that cannot be recovered from) is considered undefined behavior.
See below. Brian -- Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header.
Jordan Abel < XXXX@XXXXX.COM > writes: I'm fairly sure it is, since the standard doesn't define what the behavior is. -- Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.**--****.com/ ~kst> San Diego Supercomputer Center <*> < http://www.**--****.com/ ~kst> We must do something. This is something. Therefore, we must do this.
I guess i'm used to thinking of UB as something that can at least in principle be identified by careful examination of the source. that is, for any given set of inputs ["inputs" including returns from library functions whose outputs are not fully determined by their inputs - e.g. malloc returning null or not], a program either does cause UB or doesn't. stack overflows are a big hole in this, and i think they're unique.
Are they UB and are they unique? I'd categorise them as an environment constraint violation, another example would be opening more files then the operating environment permits. Stack size is environment specific, so a well formed program that operates correctly in one environment might violate the constraints of another. -- Ian Collins.
That doesn't cause UB. It causes fopen to return a null pointer. Which is unique among ALL things which cause UB.
OK. How about dereferencing an odd address on a target the doesn't support this? -- Ian Collins.
Things that would cause this to happen ALWAYS cause UB. UB doesn't always mean something bad happens.
This is allowed in C and performs the obvious useless recursive call. It is forbidden however in the C++ standard
In C it is of primary use in writing obfuscated code. C++ needs no assistance in this respect, and thus can dispense with the capability. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson More details at: < http://www.**--****.com/ ; Also see < http://www.**--****.com/ ;
XXXX@XXXXX.COM said: Not a lot. It's legal C, but eventually you'll run out of something or other, depending on what system you are using. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.**--****.com/ email: rjh at above domain (but drop the www, obviously)
1.int main(int argc, char *argv[] ) vs int main(int argc, char **argv )
Is this a style thing? int main(int argc, char *argv[] ) or int main(int argc, char **argv ) i.e. *argv[] or **argv Why choose the latter?
2.int main() or int main(void)?
Hi, guys! I met a problem: Should I use "int main()" or "int main(void)", is that a kind of "style" problem? And which is the standard C99 recommend? If it's a "style" one, where can I get the standard or nearly standard C style? K&R or what? Thanks a lot! Frederick Ding 2005-12-3
3.int main(void) { return main(); }
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its rundos.exe, it says the program exits with a return value of -1073741819 (i.e. -2^30 + 5) after 0.032 seconds or so. Why? -- #include <stdio.h> #include <stdlib.h> int main(void) /* Don't try this at home */ { const size_t dim = 256; int i; for (i=0; malloc(dim); i++) /*nothing*/ ; printf("You're done! %zu\n", i*dim); puts("\n\n--Army1987"); return 0; }
4.int main(int argc, char *argv[] ) vs int main(int argc, char **argv )
Sidney Cadot < XXXX@XXXXX.COM > wrote in message news:<budvlg$6v7$ XXXX@XXXXX.COM >... > August Derleth wrote: > > > [...snip...] > > > int crc32(char *buf, int len); > > > > Would compute the 32-bit cyclical redundancy check of a buffer > > containing character values. > > Wouldn't it be more appropriate if the return type was unsigned? The > resulting value denotes a polynome with binary coefficients, and there > is nothing to justify a special meaning for the sign bit. > > Forthermore, if you use signed ints inside the routine, you are going to > do bitwise operations on signed numbers, which may give headaches > concerning portability. > > (By pretty much the same token, I'd make the buf's base type an unsigned > char.) I'd shoot for... unsigned long crc32(const void *, size_t); -- Peter
5.What does MAIN_ _MAIN_ __MAIN__ mean?(to invoke clapack)
6. Main procedure inside a package?
Users browsing this forum: No registered users and 56 guest