help on free() for huge pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpdar
    New Member
    • Nov 2008
    • 2

    help on free() for huge pointer

    typedef struct FileHdr
    {
    unsigned long reg;
    unsigned short width;
    float sfactor;
    struct FileHdr huge *next;
    }FileHdr;
    FileHdr huge *Hdrhead=NULL,h uge *Hdrcur=NULL;
    //
    //
    Hdrhead=(FileHd r huge *)malloc(sizeof (FileHdr));
    //some operation
    free(Hdrhead);

    when i try to free huge pointer i get a warning stating suspicious pointer conversion
    is there any other best way to free huge pointer
  • arnaudk
    Contributor
    • Sep 2007
    • 425

    #2
    The name of your struct and the typedef are the same.

    Comment

    • cpdar
      New Member
      • Nov 2008
      • 2

      #3
      Originally posted by arnaudk
      The name of your struct and the typedef are the same.
      I hope that is allowed, i can do all the operation that i want to, but i am not finding way to release used memory (huge pointer).

      Comment

      • arnaudk
        Contributor
        • Sep 2007
        • 425

        #4
        In:

        struct FileHdr huge *next;

        What does "next" point to? As far as I can tell, struct FileHdr is the type specifier, so what is "huge"? Also, watch out when you delete the pointer to FileHdr as it looks like you could loose the pointer to the next FileHdr (Hdrhead->next) so its memory can never be freed.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          The problem is that you are passing a huge pointer to free

          For those that don't know some platforms allow specifying pointer semantics relevant to the memory model in use. the huge indicates the type of pointer and where it can point. huge was memory model available in 16 bit Windows (WIN16, Windows 3.1x and earlier).

          That is the suspicious conversion, an implicit cast away of the huge pointer semantics.

          You don't get an error on cast void * to void huge *, when mallocing, because that is a valid conversion, any void * can be represented by a void huge * but not any void huge * can be represented by a void * hence the error when calling free.

          Because malloc returns void * use of the huge pointer semantics is pointless you could just as well remove all those voids and the code should still work (and be more portable).

          What platform are you using?

          Comment

          • arnaudk
            Contributor
            • Sep 2007
            • 425

            #6
            Originally posted by Banfa
            For those that don't know some platforms allow specifying pointer semantics relevant to the memory model in use. the huge indicates the type of pointer and where it can point. huge was memory model available in 16 bit Windows (WIN16, Windows 3.1x and earlier).
            Interesting, that's why I didn't find it in my Stroustrup...
            PS: I see now that near, far and huge pointers date back to the pre-i386 days.

            Comment

            Working...