News for hackers. Stuff that matters.
Re:Dennis Ritchie's first C compiler on Github by brianberns on Wednesday May 22, 2013 @02:17AM (#5749194)

    if(foo)
I avoid doing this because it looks like a function call.
Re:Dennis Ritchie's first C compiler on Github by kybernetikos on Wednesday May 22, 2013 @03:26AM (#5749357)
In an appropriately powerful language, it could be a function call.
Re:Dennis Ritchie's first C compiler on Github by TheBoff on Wednesday May 22, 2013 @04:20AM (#5749496)
This is all very well if you have a friendly, high level scripting language like Ruby, but I'm definitely glad I don't have to write a C compiler where functions can take arbitrary blocks of code.
Re:Dennis Ritchie's first C compiler on Github by rat87 on Wednesday May 22, 2013 @10:02AM (#5750863)
> In an appropriately powerful language, it could be a function call.

> This is all very well if you have a friendly, high level scripting language like Ruby, but I'm definitely glad I don't have to write a C compiler where functions can take arbitrary blocks of code.

That's a surprisingly good setup because in Smalltalk(one of ruby's main ancestor languages)

if/else is a method which takes a block closure.

    a ifTrue: [ l log: 'a is true'] ifFalse: [ 'a is false']
while

in ruby if else is a syntatic construct

    if a
        l.log ('a is true')
    else
        l.log ('a is false')
    end
probably more for perceived clarity/comfortability then speeds sake.
Re:Dennis Ritchie's first C compiler on Github by swift on Wednesday May 22, 2013 @05:30AM (#5749688)
Re:Dennis Ritchie's first C compiler on Github by a1369209993 on Wednesday May 22, 2013 @04:10AM (#5749473)
after

  #define if(X) LET(_it,X) if (_it)
it would be a macro call
Re:Dennis Ritchie's first C compiler on Github by yoklov on Wednesday May 22, 2013 @08:00AM (#5750150)
I'm fairly certain that shadowing a keyword with a macro is forbidden by the standard (or invokes UB?) but this will still work for most compilers, provided LET is defined reasonably. Hm, something like

     #define LET(name, X) \
       for (int let_once_=1, name=(X); \
            let_once_; \
            let_once_=0)
may be reasonable, though tokenpasting in __LINE__ for good measure might be necessary for nesting.
Re:Dennis Ritchie's first C compiler on Github by 30thElement on Wednesday May 22, 2013 @09:59AM (#5750850)
Shadowing keywords is perfectly valid, although I believe you can't shadow keywords in standard headers so that compiler writers don't need to worry about it. It gives rise to some "useful" C/C++ features that should never be used, like if you want to access private members in foo.cpp, do

     #define private public 
     #include "foo.cpp"
     #undef private
Re:Dennis Ritchie's first C compiler on Github by TazeTSchnitzel on Wednesday May 22, 2013 @12:24PM (#5751908)
I can imagine some insidious menace adding this to the top of a file:

    #define public protected
Re:Dennis Ritchie's first C compiler on Github by yoklov on Wednesday May 22, 2013 @03:51PM (#5753291)
I once someone jokingly do (the second only always works in C, not C++)

    #define else
    #define struct union
Evil!
Re:Dennis Ritchie's first C compiler on Github by breadbox on Wednesday May 22, 2013 @01:54PM (#5752561)
Which is exactly why you don't do it in a language where it isn't.
Re:Dennis Ritchie's first C compiler on Github by kybernetikos on Thursday May 23, 2013 @01:42AM (#5755522)
Why should a developer have to have headspace for a special class of construct? And what difference does it make in practice whether it is a keyword or a function - why do you think it's so important that they are obviously different in the code - does their being part of a special category have any practical implications?