far and near

This is a discussion on far and near within the C Programming forums, part of the General Programming Boards category; hello all, i've been struggling with this problem for a while, with no success. it is in regard to far ...

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

    Unhappy far and near

    hello all,

    i've been struggling with this problem for a while, with no success.

    it is in regard to far and near interaction.

    when it is instructed to perform the the copying of 'gA\0' (line 100, 101, 102) appears to be ignored.

    someone has mentioned that since i am performing the three lines in local scope, hence near data, therefore that would be an issue, but is there a way around it? if so how?

    I'm sure there is someone out there who has had this particular problem with 64k block memory modules, and non-linear memory



    Code:
    // global variables
    byte far far_string[3] = { 'h', 'J', 0};
    byte      near_string[3] = { 0 };
    
    // <main.c>
    void main( void )
    {
     test();
    }
    
    // <far.c>
    void test( void )
    {
     far_string[0] = 'g'; // line 100
     far_string[1] = 'A'; // line 101
     far_string[2] = 0;  // line 102
    
     puts_lcd();             // this routine will display on the lcd but it
                                   // displays it as hJ and not gA??
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's a novel idea, how about you get a real compiler, instead of that old ass Turbo C 3.0 that you're using. (That's it, isn't it? That's the "old compiler of choice".) Oh, wait, I've already said this, because you keep posing the same problem over and over.

    Really, get a new compiler. They're free. Go, download one, save yourself the trouble.

    [edit]
    *sigh* Digs out Turbo C++ 3.0 for Windows manual...
    Page 56
    Assignment restrictions also apply to pointers of different sizes (near, far, and huge). You can assign a smaller pointer to a larger one without error, but you can't assign a larger pointer to a smaller one unless you are using an explicit cast. For example,
    Code:
    char near *ncp;
    char far *fcp;
    char huge *hcp;
    fcp = npc;                // legal
    hcp = fcp;                // legal
    fcp = hcp;                // not legal
    ncp = fcp;                // not legal
    ncp = (char near*)fcp;    // now legal
    So, in closing, get a new compiler because I'm putting my book away in the closet again.
    [/edit]

    [edit2]
    Looks like you'll need more than that.
    Page 52
    The near, far, and huge modifiers can also be use as function
    type modifiers; that is, they can modify functions and function
    pointers as well as data pointers. In addition, you can use the
    _export, _loadds, and _saveregs modifiers to modify functions.

    The near, far, and huge function modifiers can be combine with
    cdecl or pascal, but not with interrupt.

    Functions of type huge are useful when interfacing with code in
    assembly language that doesn't use the same memory allocation
    as Trubo C++.

    A non-interrupt function can be declared to be near, far, or huge
    in order to override the default settings for the current memory
    model.

    A near function uses near calls; a far or huge function uses far call
    instructions.

    In the small, and compact memory models, an unqualified func-
    tion defaults to type near. In the medium and large models, an
    unqualified function defaults to type far.

    A huge function is the same as a far function except that the DS
    register is set to the data segment address of the source module
    when a huge function is entered, but left unset for a far function.
    ...
    That should suffice. The book is going away now. Get a new
    compiler.
    [/edit2]

    Quzah.
    Last edited by quzah; 06-27-2004 at 10:28 PM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    28
    Yes I've read that manual already, it does explain the far to near issue but that is with pointers.

    The problem is I can't get another compiler.

    oh well. thanks for trying

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read the second edit. That isn't dealing with pointers.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    you cant get another compiler because you are programming an old machine? or you didnt know about MinGW32/DJGPP

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    > The problem is I can't get another compiler.
    Why not?

    Your machine seems up to the task of browsing the internet, so it should be able to run a decent compiler.
    There are plenty of free ones - see http://www.compilers.net/Dir/Free/Compilers/CCpp.htm

    If it's your course requirement that you need this old fossil, get a better course!
    You're not going to learn much of any relevance from such a backward tutor.

    > byte far far_string[3] = { 'h', 'J', 0};
    Which file is this in?

    > far_string[0] = 'g'; // line 100
    If it's not far.c, how did you declare the extern array?

    > puts_lcd();
    Ewww - icky global variable interface.
    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.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    someone has mentioned that since i am performing the three lines in local scope, hence near data, therefore that would be an issue, but is there a way around it? if so how?
    What kind of memory model are you using? You can change this under the Options menu.

Popular pages Recent additions subscribe to a feed

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