DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2005
    Posts
    58

    Question what is the meaning of this macros?

    1>
    define xbooluninit ((xbool) 0x81);

    2>
    define log(what) logout(0,what);

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    the first makes a constant expression -- from the name i would expect to see
    xbool somevar = xbooluninit;

    the second creates a new function from an old to hide the first parameter, which the
    programmer always wants to be zero. I disagree with this programming style, all you save is a zero after creating chaos.

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    Quote Originally Posted by jonnin
    the first makes a constant expression -- from the name i would expect to see
    xbool somevar = xbooluninit;

    the second creates a new function from an old to hide the first parameter, which the
    programmer always wants to be zero. I disagree with this programming style, all you save is a zero after creating chaos.
    Both macros are hideous. The former can be expressed as a const, or enum with less likelihood of introducing bugs. Both, btw, incur at least one bug: they have a semicolon at the end, which is a serious problem if you use them inside an expression. As for the latter macro, overloading and default argument values are a much, much better option.
    Danny Kalev

  4. #4
    Join Date
    Jan 2005
    Posts
    26
    This code compiles and runs using the borland commandline compiler

    #include <iostream>

    #define STARTOFPROGRAM int main() {
    #define ENDOFPROGRAM return 0; }

    #define BEGIN {
    #define END }

    #define STARTOFARGS (
    #define ENDOFARGS );

    #define ENDOFSTATEMENT ;

    #define MAKEVAR(type, name, value) type name=value;

    using namespace std;

    void print(int i)
    BEGIN

    cout << i;

    END

    STARTOFPROGRAM

    MAKEVAR(int, i, 0);
    print STARTOFARGS i ENDOFARGS

    ENDOFPROGRAM

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    Some not quite bright person has tried to make c look more like pascal, instead of learning the correct way to program. Throw this code away as soon as you can!

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    I think it compiles and runs with any C++ compiler but that's not the point. This codfe is horrific. I don't want to start preaching why it's awfully terrirble. As jonnin said, just throw it out of the window. Even Pascal programmers wouldn't bear it.
    Danny Kalev

  7. #7
    Join Date
    Dec 2003
    Posts
    3,366
    There are a lot of things you CAN do that work just fine. Ive posted this before, but this is an example of how bad a short program can be. You have to run it to see what it does. Which makes the point: just because you can do something, and just because it works, does not mean its acceptable.

    typedef double stype ;
    void ss(stype *list , const int size)
    {
    stype temp;
    int i, j, dx=0;
    int harr[] = {0, 1,10,53,105,542,1047,6239,16256,56720,134096,
    579823,1000000,5430201,999999999 };
    while(size/2 > harr[++dx]);
    for(dx--;dx;dx--) {
    const int hdx = harr[dx];
    for( i = hdx, temp = list[i]; i< size; temp = list[++i])
    {
    for(j = i; (j >= hdx) && (list[j-hdx] > temp);
    list[j] = list[j-hdx], j -= hdx);
    list[j] = temp;
    }
    }
    }

  8. #8
    Join Date
    Nov 2003
    Posts
    4,118
    And mroe generally speaking: that's what characterizes bugs. The code comiles and links just fine, but that certainly doesn't guarantee that it's correct, stable or reliable.
    Danny Kalev

  9. #9
    Join Date
    Jan 2005
    Posts
    26
    Some not quite bright person has tried to make c look more like pascal, instead of learning the correct way to program. Throw this code away as soon as you can!
    I can throw it away now if you like. Trust me, I write code the correct way, I just posted this code to entertain readers. And also, trust me, there are worse ways to write code, for example, one person wrote a bunch of macros to make it so he could program in c using ebonics.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links