Is there any limitation with casting objects (or pointers) allocated in static memory? (not in heap) I think so but I will like if someone can supply me more about this.
The limit is only that the stack is a limited size (so is the heap, for that matter). If you can create the object on the stack (the limit has not yet been hit) then you can create a reference to it (if the pointer also fits on the stack). Is this what you meant?
Say you create a void pointer:
If you want to cast *p to a wider pointer, are you restricted by the layout in stack of *p and f?
you can do
p = (Foo) &(f);
p does not matter. its a word sized place on the stack that contains the memory address that you put into it. Unless you are on some odd system that has near and far and all that? I don't even remember how near and far work, but I don't think you can cast them around -- I think you have to create it like far void* fp, near void* np etc.
You can't change the size of f either. You can't do a realloc to a pointer that points to stuff on the stack. Is that what you mean? you can try it and it will crash, and you can go off the end of f and that will also crash, just like any pointer!
I still am not sure I understand what you want to do??
I think you got me.
p = (Foo) &(f);
what about if Foo* is larger than void*? Thatīs the point I am trying to reach.
First off, jonnin must have meant:
Originally Posted by FededS
there is no such possibility. a void * variable should be large enough t contain the largest possible data pointer. Technically speaking, this is mostly applicable to DOS style segmented architectures, which are pretty much extinct these days. Mainstream systems use uniform pointer sizes, so sizeof(void *) should be the same as sizeof(Foo*). However, as I said, even if there are systems with different pointer sizes, void* should be the largest one.
So does the compiler scan every type in the source files and then decides the size of void *? Is that ok?
one last time:
all pointers are the same size.
They are the size of a word on your machine.
sizeof(int *) == sizeof(char *) = sizeof(ofstream *) .....
with a few exceptions, most notably DOS.
This is not the same as saying something about the size of the memory block that the pointer points to. THAT is a different concept. The compiler does not know or care about that. Its up to the programmer to know and use allocated memory or references to arrays or whatever correctly.
and yes, I typo'ed -- the * got lost between my head and the keyboard. sorry about that.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL