I have come across some code that looks like it is forward declaring a struct but I can not find any definition for the struct in the code base. It seems to be used as though the struct was defined. Could someone explain why the below code is valid c++?
What type is Frame? What is the size? I cannot use sizeof() as it will complain it is undefined.
I am trying to convert a similar piece of code to Visual Studio 2015 from 2010. The reinterpret_cast cast is complaining that it cannot be converted due to the fact that
'reinterpret_cast': conversion from 'unsigned long' to 'Frame *' of greater size
#include <stdio.h>
struct Frame;
int main()
{
unsigned long currentFrame = 5;
Frame* frame = reinterpret_cast<Frame*>(currentFrame);
printf("%p", frame);
}
GCC 4.9.2 was used to compile this example.
I understand the error, but do not understand how the struct is being used. Is it defaulting to int?
struct Frame;is an incompletestructdefiniton. That is you can pass around pointers toFramebut you cannot dereference pointers toFrame. ll that can be said is :struct Frame*is a pointer to some unknownstruct.conversion from 'unsigned long' to 'Frame *' of greater sizemeans that'unsigned longis smaller thanstruct Frame*as you compile for 64 bits. So the size ofunsigned longis 32 bits bujt the size of a pointer is 64 bits. - Jabberwocky