Skeen
Skeen

Reputation: 4722

Unexpected compiler error (Superfluous Cast?)

I'm currently in the process of writing my own kernel bottom up, and I've come across this little issue in my linear memory manager, that I can't seem to understand.

I've got the following piece of code; void* end_page_address = /*(void*)*/ 0x3FF000;

However, when the void pointer cast is disabled, I get the following error by g++;

src/paging/LinearMemoryManager.cpp: In constructor 'LinearMemoryManager::LinearMemoryManager(PhysicalMemoryManager*)': src/paging/LinearMemoryManager.cpp:87:42: error: invalid conversion from 'int' to 'void*' [-fpermissive]

How come? - Because it's apparently not generally needed, as the line just above it compiles just fine without a cast:

void* start_page_address = 0x00000000;

Upvotes: 0

Views: 399

Answers (1)

I think that the NULL pointer, which has address 0, (even written as 0x00000 or similar), deserves a specific treatment in the C++ specification (and inside the GCC compiler). BTW, C++11 added nullptr and its type with good reasons.

But non-zero addresses like void* end_page_address = (void*) 0x3FF000; need an explicit cast.

I hope you are aware of C++ tricks (exceptions, constructors, RTTI, ...) when coding a kernel with it. You might need to understand exactly how your particular version of g++ handles them.

I also hope your kernel is free software (GPL-ed), and that you follow the "release early, release often" motto. I'll be curious to look inside its source code.

Upvotes: 1

Related Questions