Memory Layout

This is a discussion on Memory Layout within the C Programming forums, part of the General Programming Boards category; I should probably know this, but... I'm writing a series of functions that return pointers to objects. In the case ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    Memory Layout

    I should probably know this, but...
    I'm writing a series of functions that return pointers to objects. In the case that an error occurs I am returning a hex value instead of a pointer.
    My return codes start at 0x00000 and I'm planning to have around 20-50.
    I have investigated many pointers with my debugger and noticed that pointer values are generally much higher than this. Is this purely by coincidence or is it safe to assume a certain range that will NOT interfere with memory in my application?

    ***edit***
    Forgot to mention that my target system is current versions of windows (XP to 7).
    Last edited by chris.r; 04-18-2010 at 01:05 PM. Reason: Clarification

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Yes, I believe the lower addresses are used by the system. However, I think you should consider an alternative method of returning error codes.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Why not return NULL when an error occurs. That's the convention for pointers atleast.
    And any address return'd will be logical so there's no conflict between user / kernel space.

  4. #4
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    itcbitc, He also wants to return information about the error, but I'm guessing he doesn't want to make extra room for the error code.

    This might be slightly more convenient for you right now, but I (along with most others) would consider relying on the value of pointers (other than 0/NULL) to be poor practice.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    Quote Originally Posted by NeonBlack View Post
    itcbitc, He also wants to return information about the error, but I'm guessing he doesn't want to make extra room for the error code.

    This might be slightly more convenient for you right now, but I (along with most others) would consider relying on the value of pointers (other than 0/NULL) to be poor practice.
    Yes, I'm trying to create code that provides error information so I can deal with it in calling functions.
    I suppose this method isn't very expandable. I suppose the best way to deal with this would be to create a separate error handling class?

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Well you could return hex values looking something like this. That if you want to do it the way wanted it to be

    Code:
    #define RET_CODE_1       0x200
    #define RET_CODE_2       0x201
    #define RET_CODE_3       0x202
    #define RET_CODE_4       0x203
    #define RET_CODE_5       0x204
    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  4. memory layout and declaration
    By cbastard in forum C Programming
    Replies: 6
    Last Post: 09-13-2005, 12:24 PM
  5. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM

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