4 ms·
He probably thought pointers are the only kind of variables and that he needed to dereference them. I imagine something like int *a = 1, *b = 2; printf
by cldr 13y ago
He probably thought pointers are the only kind of variables and that he needed to dereference them. I imagine something like
int *a = 1, *b = 2;
printf("%d\n", *a && *b);
Either that or he used `%s` as a format specifier. That seems more probable.
Edit: Or, as I just realised the people below me meant,
printf(a && b);
- chewxy 13y agoNah mate, it's just some compiler flag that I didn't turn on (don't know which. my gcc-fu is fail since it's been really a long time since I touched C)
- cldr 13y agoJust for my curiosity's sake, would you mind posting the code you tried that segfaulted?
- georgemcbay 13y agoYeah I'm dying to see the original C code but it isn't on the page anywhere, AFAICT. From the article, about the C version: "Mine hadn't worked, which I suspect is some sort of compiler issue." Yeah I'm going to go out on a limb and proclaim that there's no way this was due to a compiler "issue" in gcc. Not that gcc is perfect, but there's no way it is barfing on one of these handful of line programs that does nothing but some logical operations and printfs.
- cldr 13y agoMy thoughts too.
- chewxy 13y agoNope. The answer is still I suck at C. Parts of the blog post was written late last night (about 3 am), and parts of it was written on my commute to work. I tried to rewrite what I wrote last night and tried to compile it on my work computer, and all I got were warnings. So... can't recreate. Sorry
- eridius 13y agoIt's not a compiler flag, I guarantee it. Your code was simply incorrect. The only thing a compiler flag might have done was turn on a warning that would have told you what you did wrong (depending on what, exactly, you did do wrong).
- deleted 13y ago[deleted]
- cldr 13y agoYes it will: http://ideone.com/DYmxj0 http://ideone.com/DYmxj0
- rayiner 13y agoOr didn't put a format specifier, which makes sense coming from languages that don't have one in their print statements.
- cldr 13y agoNot putting a format specifier wouldn't cause a segfault.
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- cldr 13y agoWell, there is a difference between "format specifier" and "format string". The first argument to printf is the format string, the `%d` and `%s` type things are the format specifiers. I was talking about this printf("Hi", 45); which will not segfault. If you meant printf(45); Then you are absolutely correct, that would segfault on common machines.
- comex 13y agoDeleted my comment because you are, of course, correct. (However, I do suspect rayiner was referring to omitting the format string.)
- cldr 13y agoI think so too, I just have bad reading comprehension and should have known but didn't.
- Danieru 13y agoI think that must be it. And it makes perfect sense how he would hit it. Example: http://ideone.com/MilaUN http://ideone.com/MilaUN