varible declartion

This is a discussion on varible declartion within the C Programming forums, part of the General Programming Boards category; hello here is my problem char far s,s2; what is far in the above statement. and how it differs with ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    17

    varible declartion

    hello

    here is my problem

    char far s,s2;

    what is far in the above statement.
    and how it differs with ordinary one.

    thank u
    bye
    srinu
    srinu

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    In DOS, far pointers are used to access memory outside it's normal reach (SEGMENT). It access the memory in the fashion SEGMENT:OFFSET.
    Example, to access the Video RAM, which is located at: B800, you would decalre a far pointer like:

    Code:
    unsigned char far *addr = 0xB8000000;
    The leading zeroes is the OFFSET in the SEGMENT. Thus, a far pointer has two parts, SEGMENT:OFFSET, whose physical address is got by:

    PHYSICAL ADDRESS = (SEGMENT << 4) + OFFSET;
    which creates a 20bit address. Thus, the reach is till 1MB with this kind of a pointer.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    far & huge pointer

    for every c program in execution, there is sth called address space where memory space is allocated for ur variables..( stack , heap, etc..) are located..
    every program has its own address space..which is 64k.. and one program cannot normally access data from another address space (there are ways to do this also..) ..
    for accessing 64k u dont ned need more than 2 bytes (16 bits coz 2^16= 64k )...
    so a pointer is of 2 bytes.
    but if u want to access data outside the address space then u need bigger pointers. so far and huge pointers are used here. they have a size of 4 bytes and can access data from anywhere in the hard-disk. (i dunno how..tacitly assumed)

    u should ahve hearsd that c can be used to write viruses and all tht stuff. so here u r trying to rwite into address space of another program.. here u have to use far pointers.

    hope ur puzzle is solved.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Interesting. How might you output the contents graphically?(what interrupt?)

    Had fun displaying the values, tho...

    Code:
    
    
    int main()
    { 
    unsigned x = 0xB8000000;
    unsigned char far *addr;
    
    *addr = x;
    
    unsigned char far *a;
    
    
    
    for (a = addr; a != NULL; a++)
     {
      printf(":: <Addr>: [Hex]-  %p  [Int]- %6i       <Contents>: %4i     \n"
              , a, (int)a, (int)*a);
      Sleep(300);
     }
    
    
    
    
    return 0; 
    }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turning a varible into a global.
    By Queatrix in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2005, 06:58 PM
  2. accessing varible in a c++ class
    By jccharl in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 02:01 PM
  3. Randomize Varible
    By Hussa in forum C++ Programming
    Replies: 5
    Last Post: 01-10-2003, 09:12 AM
  4. Array Varible
    By Jonh in forum C++ Programming
    Replies: 4
    Last Post: 01-09-2003, 05:31 PM
  5. Varible is different once returned.
    By epoch in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2003, 01:45 AM

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