pre-processor

This is a discussion on pre-processor within the C++ Programming forums, part of the General Programming Boards category; Im trying to understand how a c++ class. What does this mean : Code: #define Sequencing(S) {char Dummy; StackBottom = ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    291

    pre-processor

    Im trying to understand how a c++ class.

    What does this mean :
    Code:
    #define Sequencing(S) {char Dummy; StackBottom = &Fummy; S;}
    
    // later used like this :
    Sequencing(TestProgram())
    Also

    Code:
    #define Synchronize // {jmp_buf E, if (!setjmp(E) longjump(E,1);}
    //later used like this :
    Synchronize;
    And a more general question :
    What is the difference between
    const int SIZE = 100;
    and
    #define SIZE 100
    ?

    Thanks for any response.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    The compiler will search for Sequence(S) in your code and replace it with {char Dummy; StackBottom = &Fummy; S; }

    So Sqeuencing(TestProgram()) will be replaced by the compiler with:
    Code:
    { char Dummy; StackBottom = &Fummy; TestProgram(); }
    #define vs const

  3. #3
    blurrghh
    Guest
    avoid macros like that, its not too easy to read as you can see!

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Inline functions and const variables are prefered when working with C++. A search of the board will give you a million reasons why.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Originally posted by Monster
    The compiler will search for Sequence(S) in your code and replace it with {char Dummy; StackBottom = &Fummy; S; }

    So Sqeuencing(TestProgram()) will be replaced by the compiler with:
    Code:
    { char Dummy; StackBottom = &Fummy; TestProgram(); }
    #define vs const
    Thanks for your reply.

    Another question, in the header file I've got this line
    Code:
    extern char *StackBottom;
    In the source file it's declared as :
    Code:
    char *StackBottom;
    Why is this ?

    one more question,
    Code:
    char *StackButtom;
    something::something(size_t Dummy = 0)
    {
      char x;
      if (StackBotton)
        if(&x < StackBottom ?
          &x <= (char*) this && (char*) this <= StackBottom :
    &x >= (char*) this && (char*) this >= StackBottom)
    printf("Attemp to allocated on the stack");
     }
    First, what kinda variable is size_t ?
    I have no idea what the second if statment does, any help would be great ?

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    extern means: tell the compiler it's declared somewere else

    If you have for example 2 source files, both using (sharing) the same var, you cannot declare it in both files. You declare the var in one source file ( int global_var; ) and in the other file you tell the compiler that the var is declared somewere else ( extern int global_var; ).

    It's strange that the keyword extern is used in a header file. I'm not sure why you need to do that!
    Last edited by Monster; 11-29-2002 at 10:00 AM.

  7. #7
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    The size_t is defined in stdio.h , stdlib.h , stddef.h , and string.h
    It's used for several functions to indicate the size of 'things' (like the sizeof operator). The variable size_t is on most compilers a signed or unsigned int.

    Took this from the stdio.h on my PC:
    Code:
    #ifndef _SIZE_T
    #define _SIZE_T
    typedef unsigned int    size_t;
    #endif
    But this doesn't mean it's an unsigned int on your system.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Thanks for your reply Monster.

    I dont understand the purpose of size_t if it's the same as signed int or unsigned int.

    Code:
    char *Stack
    constructor (size_t Dummy = 0)
    {
      char x;
      if (&x < Stack ? 
         &x <= (char*) this && (char*) this <= Stack :
         &x >= (char*) this && (char*) this >= Stack )
        cout << "Attempt to allocate the stack" << endl;
    
    }
    Can anyone please explain what this does ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Intel syntax on MinGW ?
    By TmX in forum Tech Board
    Replies: 2
    Last Post: 01-06-2007, 08:44 AM
  2. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 07:23 AM
  3. Pre Processor output
    By siavoshkc in forum C++ Programming
    Replies: 5
    Last Post: 08-11-2006, 05:32 PM
  4. Is this processor 64-bit?
    By ChadJohnson in forum Tech Board
    Replies: 6
    Last Post: 02-11-2006, 08:18 AM

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