#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0

    'far' pointers in DJGPP & MSVC


    char far *key = 0x417;
    far pointers diclare in Turbo C like this

    but how to diclare far pointers in my code, if i want to
    compile my code with DJGPP & MSVC Compilers ???
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    >> but how to diclare far pointers in my code, if i want to
    compile my code with DJGPP & MSVC Compilers ???
    Short Answer: You don't. Simply drop the far keyword from the declaration (i.e.) char *key = 0x417;

    Far pointer types do not exist for 32 bit compilers, so you can safely remove the far from the declaration. It was a non-standard extension only present in 16 bit C compilers on intel platforms. The only reason people invented the far pointer is because Intel came up with this brain damaged segmented architecture when they designed the 8088 (the original PC chip) and the far pointer was a hack for C compilers to get around accessing memory in another segment. 32 bit compilers see the memory as a flat memory model with none of this segmented nonsense, so there's no need for them to support the far keyword.

    IIRC Intel kept 16-bit backward compatibility all the way to the 486 (possibly the pentium as well!), even though all chips up from 386 were 32 bit processors.

    Note: Fiddling with the bits on address 0x417 won't most likely do what you expect it to, in a 32 bit compiler. This is because the processor is running in protected mode and won't let you access the physical memory at address 0x417. What you'd access is virtual memory address 417, which could be located anywhere in physical memory, depending on where the OS decides to page it to. If you're thinking of fiddling with the shift/ctrl/num lock/scroll lock/caps lock LEDs, you're gonna have to come up with another scheme there. :)
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0
    thanks for information

    but
    i've a multiple document editor project... it uses far pointers all the way & it runs well in the situation of 640 k of memory.

    once we open 3 or more file the project needs more memory for loading documents.. 16 bit compilers restricted the memory of 640 k.

    so i want to compile my project in 32 bit compilers for assigning larger 640k memory for my project. but 32 bit compilers doesn't supporst far pointer.

    wat is the solution for that
  6. #4
  7. Left due to despotic ad-min
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Posts
    1,044
    Rep Power
    14
    The far qualifier when used in 16 bit compilers results in a 32 bit pointer. djgpp is a 32 bit compiler which means it's standard pointer type is functionally equivalent to a far pointer in turbo C.

    So the answer to your question is ....

    #if defined (__GNUG__)
    #define far
    #endif

    __GNUG__ is a preprocessor macro defined by all gnu compilers (including, IIRc, DJGPP).

    As to whether you should declare any char * with a value of 0x417, that depends on you. The results of doing that is compiler dependent as well.
    Last edited by grumpy; July 17th, 2003 at 09:49 AM.

IMN logo majestic logo threadwatch logo seochat tools logo