Skip to main content
GameDev.net gamedev.net
🔒 Locked

Forward Declarations and Platform Headers

Started by jollyjeffers Jul 5, 2004 at 10:19 AM 3 replies 700+ views
Original Post
jollyjeffers
jollyjeffers
Hi all, As I've been discussing in this thread: [VC++] Compile times for large projects recently, I've been looking at improving compile times. I'm starting a new thread, because this is a bit too specific to tag on the end of the previous thread. Basically, I'm familiar with the concept of forward declarations in a header file so that you don't have to #include the full definition of a class when you're just using it as a parameter/return type. However, everything I've seen is great when you "own" the header files that the class/symbol is defined in. None of what I've read covers (for example) playing the same tricks with windows.h or d3dx9.h - i.e. SDK header files that you don't really want to mess too much with (because they can change subtly if you install/upgrade the relevent SDK). As an example, due to a small hack required by my graphics engine, I need to declare the standard Win32 WndProc() as a public function. Yet it only uses the LRESULT, HWND, LPARAM etc... definitions - nothing else. #include windows.h to get ONLY those few definitions seems overkill. But I haven't quite worked out how to safely (if possible) forward declare those types so that I only need include windows.h in the main implementation file. Likewise with d3dx9.h - I really only need definitions for 'IDirect3D9', 'IDirect3DDevice9', 'IDirect3DTexture9' etc... Is there any clever way of doing this? is it safe to just forward declare ("class IDirect3D9;" at the top) these classes and then include the files in the implementation? I can see a substantial compile time improvement if my 'graphics' class definition ("Graphics.h") doesn't have to drag around a copy of windows.h && d3dx9.h... Any thoughts/hints? Cheers, Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
C-Junkie
C-Junkie
I assume you're using a precompiled header, so changing this won't really affect your compile times.
Kylotan
Kylotan
Quote:
Original post by jollyjeffers
Is there any clever way of doing this? is it safe to just forward declare ("class IDirect3D9;" at the top) these classes and then include the files in the implementation?

Yes, it should be safe. All non-member pointers are essentially identical in Win32 code, I believe. Don't worry, if there's a problem, the compiler or linker will let you know.
jollyjeffers
jollyjeffers
Quote:
Yes, it should be safe. All non-member pointers are essentially identical in Win32 code, I believe. Don't worry, if there's a problem, the compiler or linker will let you know.
Cheers Kylotan. I've tried it now - and I got it working a bit (but not enough to remove the header)..

However, I was also raising the question of "safe" because I understand that changing the DX-SDK or the Win32 Platform-SDK could well change the contents of the headers (unlikely, but possible)... such that I could really screw myself over later on.

I'll leave it for now though, off to London to see the Formula-1 cars [grin]

Cheers,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
joanusdmentia
joanusdmentia
There are also a proverbial crapload of #defines you can place before including windows.h to specify what parts of the API to include/exclude.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.