1 / 8

PreCompiler

PreCompiler. Before every program is completed, a pre-compiler processes the code. At this point the header files are included and linked This is also the time when macros are executed. All precompiler commands begin with a #. Macros. #define BIG 123 int arr[BIG];

elois
Download Presentation

PreCompiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PreCompiler • Before every program is completed, a pre-compiler processes the code. • At this point the header files are included and linked • This is also the time when macros are executed. • All precompiler commands begin with a #

  2. Macros • #define BIG 123 • int arr[BIG]; • In the temperory file, the preprocessor creates, the code is changed to • int arr[123]; • DO NOT be confused about using #defines as constants • The #define function can be used to replace one token directly with another

  3. Macros contd… • Another way to use #define is to simply state that a variable is #defined • #define BIG • Later, you can test whether BIG has been defined and action is taken accordingly. • #ifdef evaluates to be true, if the string you have declared has already been defined. • #endif REMEMBER TO END YOUR IF STATEMENTS

  4. Inclusion Guards • Your own CPP file is compiled into an OBJ file and the obj is then linked to the various header files using the linker. • Often header files that you create will use one another. • This means that you risk including files twice. • This leads to compiler errors when compiling • So we can use #ifndef as a valid way of checking for these • #ifndef OGL • #define OGL • ….. • #endif

  5. Some Do’s and Don’ts • Do use conditional compilation when you need to create more than one version your code at the same time • Do use #undef to not let stray definitions in your project • Don’t let your compilations get too complex

  6. Declaring Variables • HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; • bool keys[256]; • bool active=TRUE; • bool fullscreen=TRUE;

  7. Messages The Program interacts with the Operating System using a series of messages. Usually all the processing of these messages is done internally MSG is the structure (type) that is used for storing these messages It is the program that has control, as to whether it wants to read a message or not To see if there is a message waiting we use the following function PeekMessage(&msg,NULL,0,0,PM_REMOVE) The first parameter is to the structure that we declared, where we want the messages to be passed. This is passed as a pointer in the internal code The next three are irrelevant to any projects that we do in class The last parameter specifies what do to with the message once it has been processed. PM_remove removes the message from the queue.

  8. GetMessage • MSG m; • m.message == WM_QUIT; is one valid check for a special quit message • This comes when the program uses the PostQuitMessage(0); • In all other cases, we use the TranslateMessage(&msg) to translate the message • And dispatch it to windows with the DispatchMessage(&msg). Usually windows then adds this message and calls any callbacks that we have defined.

More Related