By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

help on free() for huge pointer

P: 2
typedef struct FileHdr
{
unsigned long reg;
unsigned short width;
float sfactor;
struct FileHdr huge *next;
}FileHdr;
FileHdr huge *Hdrhead=NULL,huge *Hdrcur=NULL;
//
//
Hdrhead=(FileHdr 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
Nov 4 '08 #1
Share this Question
Share on Google+
5 Replies


100+
P: 424
The name of your struct and the typedef are the same.
Nov 4 '08 #2

P: 2
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).
Nov 4 '08 #3

100+
P: 424
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.
Nov 4 '08 #4

Banfa
Expert Mod 5K+
P: 8,916
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?
Nov 4 '08 #5

100+
P: 424
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.
Nov 4 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.