News for hackers. Stuff that matters.
Re:Why 1 && 2 == 2 by cldr on Thursday July 18, 2013 @11:43PM (#6068197)
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);
Re:Why 1 && 2 == 2 by chewxy on Thursday July 18, 2013 @11:46PM (#6068209)
Nah 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)
Re:Why 1 && 2 == 2 by cldr on Thursday July 18, 2013 @11:47PM (#6068215)
Just for my curiosity's sake, would you mind posting the code you tried that segfaulted?
Re:Why 1 && 2 == 2 by georgemcbay on Thursday July 18, 2013 @11:54PM (#6068242)
Yeah 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.

Re:Why 1 && 2 == 2 by chewxy on Friday July 19, 2013 @12:14AM (#6068293)
Nope. 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

Re:Why 1 && 2 == 2 by cldr on Thursday July 18, 2013 @11:58PM (#6068251)
My thoughts too.
Re:Why 1 && 2 == 2 by eridius on Friday July 19, 2013 @01:03AM (#6068418)
It'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).
Re:Why 1 && 2 == 2 by rayiner on Thursday July 18, 2013 @11:50PM (#6068227)
Or didn't put a format specifier, which makes sense coming from languages that don't have one in their print statements.
Re:Why 1 && 2 == 2 by cldr on Thursday July 18, 2013 @11:53PM (#6068238)
Not putting a format specifier wouldn't cause a segfault.
[deleted]
Re:Why 1 && 2 == 2 by cldr on Friday July 19, 2013 @12:44AM (#6068370)
Well, 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.
Re:Why 1 && 2 == 2 by Danieru on Friday July 19, 2013 @01:00AM (#6068412)
I think that must be it. And it makes perfect sense how he would hit it. Example: http://ideone.com/MilaUN
Re:Why 1 && 2 == 2 by comex on Friday July 19, 2013 @12:59AM (#6068409)
Deleted my comment because you are, of course, correct. (However, I do suspect rayiner was referring to omitting the format string.)
Re:Why 1 && 2 == 2 by cldr on Friday July 19, 2013 @01:01AM (#6068414)
I think so too, I just have bad reading comprehension and should have known but didn't.
[deleted]
Re:Why 1 && 2 == 2 by cldr on Thursday July 18, 2013 @11:51PM (#6068231)