News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

"C" Programming Language - STYLE

Started by sivaji, Jan 10, 2008, 05:11 PM

Previous topic - Next topic

sivaji

Programming Stuffs in "C" - Technical Skills for INTERVIEW

STYLE

1: Here's an even neater trick:
   volatile int True_Tester = 3;
   #define TRUE (!True_Tester == !True_Tester)
   #define FALSE ((!TRUE) != (!TRUE))
   #define STR_DISSIMILAR(x, y) (strcmp((x), (y)) != FALSE)
Isn't this cool?

Very impressive. The volatile int type assures that even seemingly redundant calculations involving True_Tester will be performed, making sure that if the compiler's ANSI-compliant values of 0 for false and 1 for true vary during runtime, your program will detect it - and producing meaningful error messages if this change occurs during a boolean computation! Similarly, the STR_DISSIMILAR macro allows you to make quite clear what the real effects of strcmp() are.

However, you must be careful; if this code is included twice, it may produce errors, due to the multiple definitions of the ``True_Tester'' variable. You may wish to declare it ``extern'' /

2: Is goto a good thing or a bad thing?

Yes.

3: No, really, should I use goto statements in my code?

Any loop control construct can be written with gotos; similarly, any goto can be emulated by some loop control constructs and additional logic.

However, gotos are unclean. For instance, compare the following two code segments:
do {            foo();
   foo();         if (bar())
   if (bar())         goto SKIP;
      break;      baz();
   baz();         quux();
   quux();         
} while (1 == 0);      SKIP:
buz();            buz();

Note how the loop control makes it quite clear that the statements inside it will be looped on as long as a condition is met, where the goto statement gives the impression that, if bar() returned a nonzero value, the statements baz() and quux() will be skipped.

4: What's this ``white space'' I keep hearing about?

White space is a racist, segregational term. Implicitly, ``dark'' or ``colored'' space (i.e., the '_' character) is not good enough to separate tokens. More interestingly, the white space characters keep the other tokens apart. They say it's for parsing, but there's ample evidence the goal of white space is to keep the other characters from ``taking over'' the program. This is disguised by the description of C as ``white space insensitive'' - a simple ploy for sympathy.
Am now @ Chennai