#define visibility

This is a discussion on #define visibility within the C Programming forums, part of the General Programming Boards category; If i put a #define NAME 100 inside a file.cpp instead of a file.h, is it visible only in file.cpp ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 12:08 AM
  2. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 04: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, 12:23 PM
  4. Process visibility
    By SMurf in forum Windows Programming
    Replies: 5
    Last Post: 11-17-2003, 08:00 PM
  5. scoping visibility
    By dirgni in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2002, 03:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21