Thread: #define visibility

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    #define visibility

    If i put a #define NAME 100 inside a file.cpp instead of a file.h, is it visible only in file.cpp (or also in other moduules)??

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Unless you're doing something dumb like including source files in other source files, then your #define is limited to that single source file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    ok so basically if i want a "global" #define i put it in a file.h (and then include it where needed) and if i want a "local" #define i can put it in a file.cpp

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Quote Originally Posted by mynickmynick View Post
    ok so basically if i want a "global" #define i put it in a file.h (and then include it where needed) and if i want a "local" #define i can put it in a file.cpp
    Exactly.

    Remember that all that "#include <file.h>" does is get the preprocessor to stop reading from your source file and start reading from file.h, effectively stuffing the contents of file.h into your original source file. The resulting plain file (i.e. with no #include directives remaining) is what actually gets compiled.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ensuring Toolbar Visibility
    By SMurf in forum Windows Programming
    Replies: 1
    Last Post: 03-17-2006, 01:08 AM
  2. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 05:13 PM
  3. Method/Functions Names Visibility with SoftIce
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-19-2004, 01:23 PM
  4. Process visibility
    By SMurf in forum Windows Programming
    Replies: 5
    Last Post: 11-17-2003, 09:00 PM
  5. scoping visibility
    By dirgni in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2002, 04:16 PM