• illumz (unregistered)

    The real WTF is in that in the post's title every word's first letter is capitalized except for "the".

  • (cs) in reply to Kerry
    Anonymous:
    Anonymous:

    In my first job, I worked for a company that did all their work in Pascal. I found a rather weird pattern repeated everywhere, and upon asking, was told that these were written by the owner of the company (back when he still wrote code). Since the man is a reputed genius, obviously there cannot be nothing wrong with it...The pattern is as follows (translated to C++ because I cannot remember Pascal syntax now...):

     

    int x;

    bool first = true;

     for (x = 0; x<10; x++) {

        if (first) {

            // Do all loop initialisation here.

            first = false;
        } 

        // Normal loop body goes here. 

    }

    Notice anything slightly unusual?

     

    This construct is not all that uncommon.  But "first" needs to be defined as a non-stack based variable (static, etc) or it will be initialized to true every time.

    I've needed to use something like that now and then when something needs to be done between each iteration but not at the beginning or end. For instance (psuedocode):

    // *Contrived* example, but illustrates the general idea.
    bool first = true;
    for each str in strArray
    {
        if(!first)
            write(", ");

        write(str);
    }

    But, if all he's doing is loop initialization, then yea, that's bad.

  • fluffy777 (unregistered) in reply to Xarium
    Xarium:

    This is pedantic, I know, I'm sorry, but I can't put up with the compiler versus pre-processor being mixed-up for any longer...

    The C-preprocessor does not do any string concatenation.

    Any concatenation that occurs is the compiler not the preprocessor.


    I love finding out how little people know about the tools they use, even the relatively elite people like readers of this site.
  • Anon (unregistered) in reply to fluffy777

    Anonymous:
    Xarium:

    This is pedantic, I know, I'm sorry, but I can't put up with the compiler versus pre-processor being mixed-up for any longer...

    The C-preprocessor does not do any string concatenation.

    Any concatenation that occurs is the compiler not the preprocessor.


    I love finding out how little people know about the tools they use, even the relatively elite people like readers of this site.

    Are you saying this is wrong?


    #define MY_STRING "foo"
    printf("bar" MY_STRING "\n");

     Run through gcc -E, which only does pre-processing produces:

    printf("bar" "foo" "\n");

     

  • (cs) in reply to anonymous
    Anonymous:
    I love how elegant is C:

    THANKS GODS C IS NOT DELPHI: 

    if ( whatever) then

    begin

       foo();

    end; 

    THANKS GODS IS NOT BASIC:

    If condition Then
     Foo; 
    End If
    C IS SIMPLY RIGHT: 

     if ( condition ) foo();

    or

    if (condition) {
      foo();
    }

     

    Your Delphi example is wrong. It can be just as succinct as your first C example:

    if condition then Foo();

    In your second example, the begin and end are not much more than the opening and closing braces.

    If you are going to use examples like this, at least make them real.

  • blaaaaaaaaaaaaa (unregistered) in reply to Ownage Personified
    Anonymous:

    Forget not perl:

     if (condition) foo();

    ...

    unless (!condition) foo();

    Missing some of these: {}

    Have some of mine.  I've got plenty.

    {}{}{}{}{}{}{}{}{}{}{}{}






      

  • Greg (unregistered) in reply to illumz
    Anonymous:
    The real WTF is in that in the post's title every word's first letter is capitalized except for "the".

    The word "the" in a title is not capitalized unless it is the first word in the title.

  • Yeekus Maximus (unregistered) in reply to Anon

    It depends how you define where pre-processing stops and compilation begins.

    (The standard says that compilation behaves as if adjacent string literals are concatenated before pre-processing tokens are converted to normal tokens.) 

  • Anonymous (unregistered) in reply to Anonymous Coward
    Anonymous:

    Any standard implementation of printf should produce the desired result without the need to call printf thrice regardless of concatenation support:

     printf("configuration: %s\n",CONFIG_STRING);

     

    DING! DING! DING!  We have a winner!  Jeez, its kinda scary how many people were confused by that piece of code.

  • rycamor (unregistered)

    In response to the first example, I never knew a coder who didn't know "else", but I had to deal with one who didn't know that "else" is not *required* when using "if":

    if(condition){

        ...code

    }

    else{

       ;

    }

    And yes, he felt he had to put a semicolon in there too.
     

     

  • Mr. Sparkle (unregistered)

    The real WTF here is that he shouldn't even be using string literals in the first place. What's going to happen if he needs to localize that stuff?

  • (cs) in reply to anonymous

    Anonymous:

    I love how elegant is C:

    THANKS GODS C IS NOT DELPHI: 

    if ( whatever) then

    begin

       foo();

    end; 

    THANKS GODS IS NOT BASIC:

    If condition Then
     Foo; 
    End If
    C IS SIMPLY RIGHT: 

     if ( condition ) foo();

    or

    if (condition) {
      foo();
    }

    That isn't true at all.

    VB (or BASIC for as far as I can remember) can do the same thing as C...

    example:

    One line, one instruction per condition: 

    if condition then DoThis    

     Multiple lines, multiple instructions per condition:

    if condition then

    DoThis

    DoThisToo

    end if

     

     

    Look Ma! No semicolons or brackets!

    Looks cleaner and easier to read to me... but it is simply a matter of opinion.

     

    Let's not go starting language wars unless we actually know the syntax of other languages....

     

  • Anonymous (unregistered)

    Considering the nature of this site, the level of basic C knowledge here is just.... wow... and the readiness of people to say it's not possible is pretty "impressive" too... If you don't know what's in the C specification you're bound to either make WTF comments (like the majority of ones here) or WTF code (and compilers... in this case)

    It's also amusing that whoever wrote the code, even though it is a WTF, obviously knows more about C than most of the people commenting here...

    The most likely cause of this code is using a new (broken) compiler, and just wanting to get the damn thing to build, so going through all the errors and just adding an #ifdef  with a quick fix.

    Of course, using two if's and no fall-through else is the main WTF... and I'm sure will cause some fun with whoever has to build it with the next different compiler. (Maybe that's how "Mike" came across it?)

  • (cs) in reply to EvanED
    EvanED:
    QBASIC had else blocks... I think... hmmm, now that I write that, I'm not sure. Anyone have better memory than I?

    Yes, it does.

    Sincerely,

    Gene Wirchenko

     

  • mav (unregistered) in reply to Gene Wirchenko

    Quite frankly, I don't see any real problem with that second snippet.  Calling printf 3 times has the desired effect, even if its a bit ugly.  I just can't believe that some C compiler doesn't support that type of string concatenation...

     

  • Froot (unregistered) in reply to Blah

    Yeah, this entire thread is worthy of its own WTF. There is nothing wrong with the second snippet.

    (a) Literal string concatenation is a standard feature of C

    (b) They used that feature, and apparently it didn't work on some 'XYZ' compiler they were using. That's not a WTF.

    Working around bugs and missing features in compilers is the order of the day, especially if you are working on embedded systems with weird CPU's and corresponding weird toolchains.

    Yes, they could delete the GCC part of the clause, but that would increase the size of their binary in the GCC case because the three strings would be allocated separately in the image. And since this is likely an embeddes system, things like that matters.

    If you are going to ridicule people on the internet, please at least make it seem like you yourself are at least somewhat competent. Yes, I am talking about the editors.

    WTF, indeed.

     

  • (cs)

    Anonymous:

    Well chosen title but a part is missing:

    We have met the enemy AND HE IS US :)

     http://en.wikipedia.org/wiki/Pogo#.22We_have_met_the_enemy.....22

    Intentionally left off - I did quote it in its entirety at the end of the post.

  • Froot (unregistered) in reply to Omnifarious

    Well, golly. Maybe they didn't use other compilers than GCC and XYZ. No, making it portable to every compiler imaginable is not a good use of your time.

     

  • (cs) in reply to illumz

    Anonymous:
    The real WTF is in that in the post's title every word's first letter is capitalized except for "the".

     

    Cranky!

    :) 

  • jacob (unregistered) in reply to Froot

    I've read all the comments, and I still don't think there's a WTF in the second code snippet.  Okay, maybe it could have been written cleaner, but as Froot says: binary size matters in embedded systems.  Okay, maybe there's no #else anywhere, but is that really a WTF?

  • (cs) in reply to felix
    felix:

    Spectrum Basic (and possibly other dialects) lacked an "else" construct. Maybe the author of the first sample is a dinosaur of the 1980es? 

    You young whippersnappers - yer all soft! Back in the day of AppleBasic we had no else block. We'd number our lines and terminate our IF statements with a goto and we LIKED it. Our variables went uphill on both their letters and our strings had a dollar sign to remind us how expensive they were.

    There were games written in AppleBasic too, (not that we needed anything more than Lode Runner, Hard Hat Mack, and Rescue Raiders). Turn based strategy like Santa Paravia (how many games today let you go into debt and risk bankruptcy eh?) and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

  • Anonymous (unregistered) in reply to OneFactor

    OneFactor:
    our strings had a dollar sign to remind us how expensive they were.

    Instant win! Best part of the thread so far!

  • (cs) in reply to missing
    Anonymous:

    BTW, identifiers containing a double underscore (or a leading underscore followed by a capital letter) are reserved.  You should not use such names for your header guards.  I tend to just use FILENAME_H_INCLUDED.

    Well, I didn't know that. I've never used the GCC compiler, as all of the compilers I've used are tweaked to match the specific chip. (See my sig.) I had never heard of the double-underscore being reserved until today. In the compiler I'm using now, a SINGLE leading underscore is reserved for the names of C functions being called by the chip's internal OS.

    I don't think anyone here's heard of that, either. We just put the #ifndef __FILENAME_H etc. into our coding standard, and we based the standards on another company's standards...

    Oh.

    Yeah, this is going to get interesting. Excuse me.

    Thank you again for the chance to learn from my mistakes.

  • (cs) in reply to jacob

    Anonymous:
    I've read all the comments, and I still don't think there's a WTF in the second code snippet.  Okay, maybe it could have been written cleaner, but as Froot says: binary size matters in embedded systems.  Okay, maybe there's no #else anywhere, but is that really a WTF?

     

    The site may be named TheDailyWTF, but here, in my little corner of it, I like to call it "The Code Snippet of the Day." :)


    I enjoy these discussions  and I'm sure that I, along with a lot of lurkers have learned a lot.

    So to those brave souls who do post, wrong or right, I say Post on.

  • ChiefCrazyTalk (unregistered) in reply to aikii
    Anonymous:

    The first code snippet looks like VERY old school BASIC ( when it was spelled in uppercase, like COBOL ... ). In those ancient time, an if could only execute ONE instruction, and ( if my memories are right ) there was no 'else'. if you need several instructions, you need a gosub or a goto, indeed. This is what happen in machine code anyway, but  programmers aren't machines, I guess ...

    But the real reason is certainly near Dagon's guess. There are many embedded application specific WTF-languages around here. This 'programmer' was probably a script-kiddie with a convoluted mind due to mirc scripting, the worst language I've ever seen. In 98 there was no loops, no local variables, no arrays, quite limited conditionnal statements, non-reentrant functions ( no local variable means no stack, indeed ... unless you hack one yourself ). Any non-trivial structure needed a goto. The best thing is that the parser's behaviour changed at each version, forget about backward compatibility of scripts. It's certainly more complete now, but I would be surprised if it became any better and non-WTFesque. I know several mirc-kiddies that became 'real programmers', and as I've seen their 'progress', my guess is that this one is one of those ...

     

    I was writing BASIC code with elses (And without gotos) at least as early as 1988, and I'm pretty sure I used elses on Commodore PET Basic circa 1980.   I call fake. 

  • Tim McClarren (unregistered) in reply to Omnifarious
    Omnifarious:
    Tim Gallagher:

    Our second snippet comes from Mike who writes, "I know an intern was working on this code, but I'm afraid that it might not have been them that did this..."

    #if defined COMPILER_GCC
    printf("configuration: " CONFIG_STRING "\n");
    #elif defined COMPILER_XYZ
    /* XYZ doesn't seem to support concatenation like that */
    printf("configuration: ");
    printf( CONFIG_STRING );
    printf( "\n");
    #endif

    I find the fact that so many people are confused about the WTF here to be a WTF in itself. The code should read like this:

    #if !defined(STUPID_COMPILER)
    printf("configuration: " CONFIG_STRING "\n");
    #else /* You have a really stupid compiler that doesn't
    understand ANSI preprocessor string concatenation. */
    printf("configuration: ");
    printf( CONFIG_STRING );
    printf( "\n");
    #endif

    The basic problem is, what happens when you aren't using either GCC or the XYZ compiler? The preprocesor runs and the result is no code at all. All of the printf statements are completely eliminated. This is almost certainly not what was intended.

     
    Seriously!

    WTF!

     
    You need one line:

    printf("configuration: %s\n", CONFIG_STRING);

     

    Forget all the #if defined nonsense.

    And it works with "%" embedded in CONFIG_STRING.

    Unless you happen to be working with a fantastically broken "printf" implementation.

     

    captcha: craptastic (I'll say)



     

  • Anonymous (unregistered)

    Regarding double underscores...  From the C99 spec (6.10.8,  part 4)

    "Any other predefined macro names shall begin with a leading underscore followed by an uppercase letter or a second underscore."

    then 7.1.3: 

    "All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use."
    "All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces."

    so for header protection:

    __FILENAME_H__ is bad

    _FILENAME_H_ is bad

    __filename_h_ is bad 

    _filename_h_ is fine

    okay? great.

    And really, everybody should be following C99 in terms of this...

  • (cs) in reply to Xarium
    Xarium:

    This is pedantic, I know, I'm sorry, but I can't put up with the compiler versus pre-processor being mixed-up for any longer...

    The C-preprocessor does not do any string concatenation.

    Any concatenation that occurs is the compiler not the preprocessor.

    It is pedantic, but pedantic is good. I tested it, and you're right. It's the compiler that does it at compile time, not the preprocessor. I think that only really matters if you're skipping the preprocessing step for some reason. Though it might matter for macro expansion too. Thanks. :-) From now on, I'll refer to it as ANSI compile time string constant concatenation. :-)

  • Zlodo (unregistered) in reply to Omnifarious
    Omnifarious:
    SilverDirk:

    Back in earlier C days, you definately wouldn't want to be relying on the optimizations of your compiler to prevent a bunch of runtime string concatenation. (not that C had that ability anyway)

    The modern C++ equivalent is adding together a series of ::std::string objects, which is generally handled less efficiently than Java's string concatenation of constant strings at compile time.

    This is not the equivalent. std::string concatenation is obviously a runtime operation, whereas the concatenation of string literals by the compiler is obviously a compile time operation, so it is still useful today and does works in C++. And it is standard.

    I think the actual concatenation is done by the compiler itself and not by the preprocessor, because the preprocessor would have to first expand macros and then concatenate the strings, which would needlessly complicate its task.

    On the other hand the compiler parser can easily detect that several string literals are following each other and do the concatenation itself.



    As for using printf or string concatenation... Bleh. I'd rather avoid printf altogether if I can help it, not for performance reason in this case, but to avoid the ugly and pointless "%s" noise in the source code.

    I'd either use puts and compile time string concatenation if it is C, or iostream in C++.

    (I probably will trigger a "the real wtf if c++ operator overloading" flamewar, but in that case I can just copy and paste my posts from the last such flamewar so I don't care)
    Apparently, captcha approves of this post: awesomeness
  • (cs) in reply to Anonymous
    Anonymous:

    then 7.1.3: "All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces."
    _filename_h_ is fine

    er..um... what part of "are always reserved" did you miss?

  • Captcha: Zork. (unregistered) in reply to OneFactor

    OneFactor:
    and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

    EAMON!

     

    Plus don't forget to tell them that if you wanted high res graphics, you only got 4 colors! 

  • Anonymous (unregistered) in reply to OneFactor
    OneFactor:

    You young whippersnappers - yer all soft! Back in the day of AppleBasic we had no else block. We'd number our lines and terminate our IF statements with a goto and we LIKED it. Our variables went uphill on both their letters and our strings had a dollar sign to remind us how expensive they were.

    There were games written in AppleBasic too, (not that we needed anything more than Lode Runner, Hard Hat Mack, and Rescue Raiders). Turn based strategy like Santa Paravia (how many games today let you go into debt and risk bankruptcy eh?) and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

    I miss those golden years too. 

  • (cs) in reply to Kerry

    Anonymous:
    Anonymous:

    int x;
    bool first = true;
    for (x = 0; x<10; x++)
    {
    if (first) { 
            // Do all loop initialisation here. 
            first = false;
        } 
        // Normal loop body goes here. 
    }

    This construct is not all that uncommon.  But "first" needs to be defined as a non-stack based variable (static, etc) or it will be initialized to true every time.

    It's almost certain that he DOES want it set to true every time, but regardless, it should not be within the loop.

    If your interpretation of the code is true (it's a one time ever initialization), then the if() should be move above the loop.

    if my interpretation of the code is true (it's a first element of the loop prefix), then the code in "// Do all loop initialisation here. " should be moved above the for() with the if() and all references to first removed.

     

  • (cs) in reply to Xarium
    Xarium:

    This is pedantic, I know, I'm sorry, but I can't put up with the compiler versus pre-processor being mixed-up for any longer...

    The C-preprocessor does not do any string concatenation.

    Any concatenation that occurs is the compiler not the preprocessor.

    Nah, real pedantry would be pointing out that any "preprocessor" is an implementation detail.  The C language does not define a preprocessor.  It specifies translation phases, and every conforming implementation must behave as if the implementation performs those phases in the order in which they're specified, as far as any conforming program can determine.  An implementation can perform string concatenation in a "preprocessor" or a "compiler" or a "wombat", as long as it occurs in translation phase 6 - after character set conversion and before the conversion of pp-tokens to tokens.

    Still, points for knowing about the order of translation phases at all.  Many of the C-related comments on TDWTF just provide further evidence that far too few C programmers have actually bothered to learn the language.

     

  • Zlodo (unregistered) in reply to Ownage Personified
    Anonymous:

    (condition) && foo();

    foo() || die;

     
    This syntax actually works in a lot of languages, including C: it is perfectly legal to just have an expression as a statement, and conditional operators will only evaluate the right hand term if the left hand term is not enough to figure the result of the expression.

    I don't remember stumbling on it ever in any of the C or C++ code I worked with, though. Given the amount of people who enjoy nothing more like packing as much stuff into a single line of code, you'd expect this to be more common. 

  • Mogri (unregistered) in reply to illumz

    Anonymous:
    The real WTF is in that in the post's title every word's first letter is capitalized except for "the".

     

    That's proper style for titles. 

  • (cs) in reply to Zlodo
    Anonymous:
    Anonymous:

    (condition) && foo();

    foo() || die;

     
    This syntax actually works in a lot of languages, including C: it is perfectly legal to just have an expression as a statement

     Actually, I think you'll find a significant majority of C[++] statements are techinically just expressions evaluted for side effects. Something like "x=y;" is just such an example.

     
    But yeah, it's interesting that you don't see "foo() || abort()" around C code.
     

  • (cs) in reply to OneFactor

    OneFactor:
    You young whippersnappers - yer all soft! Back in the day of AppleBasic we had no else block. We'd number our lines and terminate our IF statements with a goto and we LIKED it. Our variables went uphill on both their letters and our strings had a dollar sign to remind us how expensive they were. ...

    You mean "AppleSoft BASIC"? :P  I remember doing stuff using both AppleSoft BASIC and Integer BASIC.

    OneFactor:
    There were games written in AppleBasic too, (not that we needed anything more than Lode Runner, Hard Hat Mack, and Rescue Raiders). Turn based strategy like Santa Paravia (how many games today let you go into debt and risk bankruptcy eh?) and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

    Wow - HMM!  I have not played that in years!  Takes me back to really fun games like Repton and DROL :)  Not to mention Lemonade (or Lemonade Stand?), which was written in Integer BASIC...! :)  Thanks for the callback!

    Peace!

  • Walrus (unregistered)

    At least there was some code in the if blocks, at my previous employer (incidentally I 'escaped' after 3 months) the lead developer loved his no-ops.....

    IF CONDITION THEN

    ****NOP 

    ELSE

    <code here> 

    END IF 

     

    OR  better still.....

    SELECT CASE TestItem

    CASE Value1

    *** NOP

    CASE Value2

    *** NOP  

    <snip>

    CASE Value14

    <code here>

    CASE ELSE

    Stop 

    END SELECT 

  • Zlodo (unregistered) in reply to EvanED
    EvanED:
    Actually, I think you'll find a significant majority of C[++] statements are techinically just expressions evaluted for side effects. Something like "x=y;" is just such an example.

    Thanks for the heads up, I wouldn't ever have guessed :p

  • (cs) in reply to Zlodo
    Anonymous:
    EvanED:
    Actually, I think you'll find a significant majority of C[++] statements are techinically just expressions evaluted for side effects. Something like "x=y;" is just such an example.

    Thanks for the heads up, I wouldn't ever have guessed :p

     That wasn't really meant for you. ;-)

     But people talk about "assignment statements" sometimes, which don't really exist. Probably some of that is just that it's a convenient, if imprecise, term, but probably in part it's not really realizing that's what's going on behind the scenes. I suspect it's quite possible to have a reasonable working understanding of C without at least explicitly realizing that.

  • (cs) in reply to EvanED

    I think it's pretty important that assignment is just another operator and can be used in an expression. It really comes in handy for loop conditions, letting one do things like "while ((c = fgetc(f)) != EOF) { ... }" rather than the awkward "while (1) { c = fgetc(f); if (c != EOF) break; ... }" or the redundant "for (c = fgetc(f); c != EOF; c = fgetc(f)) { ... }"

  • Philbert Desanex (unregistered) in reply to OneFactor

    You young whippersnappers - yer all soft! Back in the day of AppleBasic we had no else block. We'd number our lines and terminate our IF statements with a goto and we LIKED it. Our variables went uphill on both their letters and our strings had a dollar sign to remind us how expensive they were.

    There were games written in AppleBasic too, (not that we needed anything more than Lode Runner, Hard Hat Mack, and Rescue Raiders). Turn based strategy like Santa Paravia (how many games today let you go into debt and risk bankruptcy eh?) and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

    Like AppleBasic, I used a version of BASIC back in 1980 that allowed only "IF <condition> THEN GOTO <line number>".  Variable names could be only a single-letter ("A") or single-letter$ (A$).  If you had more than 26 variables you had to use arrays, hehe.  The best part was the interface:  old teletype connected to mainframe at 300 baud.

    Captcha=giggity...kinda like the sound of a teletype.

  • Hans (unregistered) in reply to Abscissa

    I'm afraid all the guy was doing was your basic loop initialisation, just as easily achieved by placing that code before the actual loop (which saves a variable, a few clock cycles, and makes the whole thing ever-so-slightly easier to understand). Which is why I thought it was "a bit funny", but hey, he owned a whole company and I had barely arrived from university, so who was I to complain?

    As for the example you give, I get that a lot lately for some reason, and it is a perfectly valid, if slightly ugly, technique.

  • (cs)

    My college roommate did it this way:

    if(....)
      ...
      break;
    else continue;
      ...
      break;

     
    "Hey John, why isn't this working?" Who needs a textbook when you can guess your way to victory?

  • Anony Moose (unregistered)

    I want to know what compiler "XYZ" was.  If it genuinely lacked that feature, well, it's hardly the biggest WTF ever, both GCC and Visual C++ have had features they took time to get right.  If it actually had the feature, then the code is more WTF-worthy.  ;) 

  • (cs) in reply to Anony Moose

    The WTF in the second part is that the programmer left the standard-dependent version in, when the workaround would work just as well on an standard compiler. It's the same WTF as checking code into version control that has buggy lines commented out.

     

  • Anonononymous (unregistered) in reply to Omnifarious
    Omnifarious:

    I find the fact that so many people are confused about the WTF here to be a WTF in itself. The code should read like this:

    #if !defined(STUPID_COMPILER)
      printf("configuration: " CONFIG_STRING "\n");
    #else /* You have a really stupid compiler that doesn't
    understand ANSI preprocessor string concatenation. */
    printf("configuration: ");
    printf( CONFIG_STRING );
    printf( "\n");
    #endif

    The basic problem is, what happens when you aren't using either GCC or the XYZ compiler? The preprocesor runs and the result is no code at all. All of the printf statements are completely eliminated. This is almost certainly not what was intended.



    The optimal solution would be just

    // Can't use string concatenation because we need to support stupid XYZ compiler
    printf("configuration: ");
    printf( CONFIG_STRING );
    printf( "\n");

    There's no need to include multiple implementations when there's one that will work in all cases.
  • blaaaaaaaaaaaaa (unregistered) in reply to rycamor
    Anonymous:

    In response to the first example, I never knew a coder who didn't know "else", but I had to deal with one who didn't know that "else" is not *required* when using "if":

    if(condition){

        ...code

    }

    else{

       ;

    }

    And yes, he felt he had to put a semicolon in there too.
     

     

     Heh... that's actually required in the coding standards of a project I just weaseled out of

    For case statements, do all selections span the selections domain exclusively and exhaustively (e.g. are all exceptions treated? Every if-then should have an else, every case statement should have a default)?

     

  • Sweet Rasberry Danish (unregistered) in reply to Captcha: Zork.
    Anonymous:

    OneFactor:
    and full fledged RPG's that not only made you deal with encumbrance but also made charisma into a useful statistic. All that with no stinking else block.

    EAMON!

     

    Plus don't forget to tell them that if you wanted high res graphics, you only got 4 colors! 

    Colors have nothing to do with resolution.  (I love the petty picking apart of others posts on this forum)

Leave a comment on “We Have Met the Enemy”

Log In or post as a guest

Replying to comment #:

« Return to Article