Thread: #define - something I need to understand

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    28

    #define - something I need to understand

    Hi all,
    I've been programming in C language for a while now, years to be realistic.
    I was looking at this file today, and I came across something that is (as an assumption) extremely easy, but for the life of me I am not able to understand it.

    #define _FAR

    #define _PTR_ _FAR *


    then the code goes on defining pointers to integers, etc...

    Throughout the years I've programmed in C, I was used to something like this:

    #define _SOMETHING 1
    #define _SOMETHING2 _SOMETHING

    which makes sense to me. I have an identifier and a string-token.

    Even saying something as
    #define _SOMETHING3

    is acceptable to me because the way I've used it is as a check
    #if defined _SOMETHING3
    or #ifndef _SOMETHING3


    My question is, how am I able to use _FAR when I do not have an actual string-token associated with it? Can someone explain to me what these two lines mean?
    #define _FAR
    #define _PTR_ _FAR *

    Thanks in advance!

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    _FAR is nothing...

    _PTR_ _FAR * is a pointer to nothing... essentially just a *

    They could have just as easily done #define _PTR_ *

    int _PTR_ x; amounts to int *x;

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The first define works for Turbo C FAR pointers, and I suspect the second line works for another compiler from those days - no clue which one, though.

    They do look weird, but don't let them rattle you, they are still the same simple token replacement and definition tool, you thought they were.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    The first one would have been better written as

    #define _FAR /* raise the dead - the zombie walks again! */

    If you see "far" in your code, then you're looking at 20 to 30 year old 16-bit DOS code.

    Macros like this are typically used to remove ancient compiler specific keywords so that the code will compile (to a fashion) on new compilers.
    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.

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    28
    CommonTater, Adak & Salem,
    thanks a lot!
    Makes sense now...

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    The first one would have been better written as

    #define _FAR /* raise the dead - the zombie walks again! */

    If you see "far" in your code, then you're looking at 20 to 30 year old 16-bit DOS code.

    Macros like this are typically used to remove ancient compiler specific keywords so that the code will compile (to a fashion) on new compilers.
    Thanks Salem.... I had fogotten all about that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RS232 connection set up
    By cs342 in forum C Programming
    Replies: 25
    Last Post: 05-26-2010, 03:57 AM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. Help getting multiple keypresses in a DOS compiler
    By Nongan in forum Game Programming
    Replies: 2
    Last Post: 04-01-2005, 10:07 PM
  4. float toolbar!
    By c-- in forum Windows Programming
    Replies: 5
    Last Post: 02-04-2003, 09:44 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM