Thread: Const and macro

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You're still allowed to do this, of course:
    Code:
    // x.hpp
    extern const int &x;
    
    // x.cpp
    int real_x;
    const int &x = real_x;
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by CornedBee View Post
    Instinctively, I'd say this is undefined behaviour.

    Less instinctively, gcc refuses to compile it if you pass the implementation file and at least one using file at the same time and use -combine. (-combine only works for C currently.)
    Compiled just fine using g++. Compiled foo.o, bar.o and then linked them

    Of course that doesn't mean it isn't undefined.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    As I said, both files at the same time and -combine:
    Code:
    gcc -o const -combine const1.c const2.c
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can't use gcc to compile c++ programs. I see that I did .c instead of .cpp, sorry about that.


    Both gcc and g++ gave me "unrecongized option `-combine`". Changing cout to printf and compiling both as C gave me a working program.

    IMO it is pretty silly to have that be undefined behavior but oh well.

  5. #35
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can't use gcc to compile c++ programs.
    Yes, you can. And it was me who changed the names to .c, because -combine is not implemented for C++.

    I don't know what GCC version you have. Mine is 4.1.2.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #36
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    3.something. Haven't had a need to update it. When I compiled the files using gcc I got syntax errors because of std::.

  7. #37
    Banned
    Join Date
    May 2008
    Location
    Four Dots Planet
    Posts
    72
    #macros are beautiful
    Code:
    #define IF if(
    #define THEN ) {
    #define ENDIF }
    #define MARRY_GO_ROUND while(1) {;}
    so sweet
    Code:
    IF 5 == 5 THEN
        MARRY_GO_ROUND
    ENDIF

  8. #38
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by (::) View Post
    #macros are beautiful
    Code:
    #define IF if(
    #define THEN ) {
    #define ENDIF }
    #define MARRY_GO_ROUND while(1) {;}
    so sweet
    Code:
    IF 5 == 5 THEN
        MARRY_GO_ROUND
    ENDIF
    Ah, so that's how VB does it! LOL!

  9. #39
    Banned
    Join Date
    May 2008
    Location
    Four Dots Planet
    Posts
    72
    Quote Originally Posted by cpjust View Post
    Ah, so that's how VB does it! LOL!
    hush hush hushssssss ... do not let the secret out lol lol lololololololololol!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Macro has same name as Function?
    By coolclu3 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 04:55 AM
  3. Defining const in a class
    By g4j31a5 in forum C++ Programming
    Replies: 5
    Last Post: 11-20-2006, 11:27 AM
  4. Is an inline function really the same as a macro?
    By Sloede in forum C Programming
    Replies: 6
    Last Post: 01-23-2004, 01:26 AM
  5. c and c++
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-12-2002, 04:50 PM