• Dean Swift (unregistered)

    Many programming languages begin as frontends to existing languages and if the language already supports some form of substitution then the tasks is significantly easier. I used the following definitions when I moved from Pascal to C:

    #define begin {
    #define end }

    Then I incorporated it into my winning IOCCC entry: http://www.ioccc.org/1996/gandalf.c

    Hey, at least I knew it was bad practice.

  • Vincent (unregistered) in reply to stonguse
    #define do_nothing    \
     __asm {              \
        noop;             \
     }
     
     
  • TC (unregistered)

    Wrong, wrong, wrong! "Forever" is spelled for(;;). Yes, I prefer the version with no space. (Some versions of GCC compare 1 to 0 if you use while(1) with no optimisations.)

    That said, it seems like he was trying to make C more like his favourite language, whatever that may be. While we're at it,

    #define begin {
    #define end }

  • wamfler (unregistered) in reply to Sam
    Anonymous:

    Oh, it's just personal preference.  He didn't like the syntax, so he changed it.  Big deal.

     

    Best comment ever. Ever.

    Ever.
  • (cs) in reply to wamfler

    Just wanted to get the 256 posts.

    What to i win??

  • NeilT (unregistered) in reply to Maurits

    Actually, based on the header provided the correct syntax is:

    repeat {
       ...
    } forever;

    I started with BDS C in the late 70s. It included the defines:

    #define   BEGIN   {
    #define   END       }

    by default. Bloody Pascal programmers :-(

    Since then I have come across:

    #define   FOREVER   for(;;)

    far too often, most conspicuously in Borland C. The argument goes: you can easily miss the ;;, but FOREVER stands out. Yeah, whatever.

    I develop and maintain embedded code. After many years of doing so I have come to a simple conclusion: the syntax is defined by the standard. Anything else is wrong because the maintainers will invariably be adversely affected by the 'better' syntax.

    Don't forget the maintenance phase is by far the longest phase for any software project - that's where you want any cost minimisation to occur.

     

  • Anonymouse (unregistered) in reply to Jeff S
    Stupid VB programmers ... wait a second ... this isn't VB .... what is this? C !? how can that be? All bad coders write in exclusively in VB, and bad code can only be written in VB!! What the heck is going on?
    You fail to see that this is what happens when a stupid VB programmer tries to impose VB style syntax on C.
  • Tom (unregistered) in reply to Poultine

    Now the maintainer has to re-interpret every "repeat { ... }untilforever" in the code into something that the rest of the C-speaking world understands without depending on kooky precompiler tricks.

    Yes, that would be confusing. What could "repeat until forever" possibly do?

  • Anon (unregistered) in reply to Gary
    Gary:
    Creating a do_nothing macro or procedure is actually useful for debugging; it allows you to place a breakpoint inside an otherwise empty "else" clause.

    With today's debuggers, you can put a conditional breakpoint on the condition.

    Yes, I've written code like

    if (x < 0) { neg = 1; } else { neg = 0; }

    but this was in the olden days. Go with your tools.

    P.S. No need to shout.

  • Scott M (unregistered)

    What no: #define then { #define end }

  • Kevin Mills (google)

    I actually really like the until and unless.

    Addendum 2017-01-26 08:26: I wouldn't do it myself in C (and certainly not in a shared project), but I do wish languages actually had those constructs built in.

Leave a comment on “The Secret to Better C”

Log In or post as a guest

Replying to comment #:

« Return to Article