Thread: Mysterious error - missing { before *

  1. #1
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582

    Mysterious error - missing { before *

    This makes no sense at all. I went through my code 4 times over and I don't see a single problem. It's causing windows menu functions to not be recognized and I don't see anything wrong. The problem seems to originate in the "stdafx.c" file which is the first include and there aren't any braces used here at all! Here's my set up:

    In the root file at the very top before anything (except comments at the top):
    Code:
    #include "stdafx.h"
    #include "My program.h"
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include "Menus.c"
    In stdafx.h (ignoring the comments at the top):
    Code:
    #define _CRT_SECURE_NO_DEPRECATE
    #pragma once
    
    #define degrees 0.017453292519943295769236907684886 // multiply by this to convert angles in degrees to radians
    
    // Modify the following defines if you have to target a platform prior to the ones specified below.
    // Refer to MSDN for the latest info on corresponding values for different platforms.
    #ifndef WINVER				// Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501		// Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
    #endif						
    
    #ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE			// Allow use of features specific to IE 6.0 or later.
    #define _WIN32_IE 0x0600	// Change this to the appropriate value to target other versions of IE.
    #endif
    
    #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    // Windows Header Files:
    #include <windows.h>
    
    // C RunTime Header Files
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <tchar.h>
    
    
    // TODO: reference additional headers your program requires here
    // common windows-related stuff
    HWND WindowHandle; // window handle
    WNDCLASSEX WindowClass; // for a window class
    MSG msg; // a message for windows
    
    int ProgramRunning = 1; // the program is running by default
    
    // string stuff
    char TextString[2048]; // a string for text to use
    
    // Debug-related things
    char DebugDetails[512]; // string for indicating errors
    double DebugTest[25]; // for displaying values
    int DebugPointerTest[5];
    
    // general variables
    char WarningString[512]; // used to display warnings and errors
    
    // other things
    
    FILE *FileHandle; // handle for reading/writing files
    When I compile just the above, I get this error

    c:\my documents\my programs\My program\My program\stdafx.h(61) : error C2143: syntax error : missing '{' before '*'

    It's causing practically every definition to be an error and it makes no sense. If I add the "{" at the top, the errors go away and windows functions are being recognized, but I get a fatal error stating of the end of the file being unexpectedly reached. How I can be getting this error in the very first include where there aren't any braces used at all?
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Perhaps your "stdafx.h" file has a curly brace missing.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are also using FILE before you have included stdio.h - I persionally wouldn't put variable and type declarations for my own program inside stdafx.h [but then I try not to have a stdafx.h at all].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You're trying to compile a header file? And you're including a .c file? No wonder stuff isn't working.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    I only use stdafx for frequently used elements that almost never change. I've removed the "FILE *" element and put it into my "Menus.c" file. This puts it after the stdio.h and everything else. Do that, however, I get a whole host of errors, involving HMENU and faulty declarations, and that error is still present. These are all my errors (repetition summarized).

    Code:
    Menus.c
    .\Menus.c(200) : error C2061: syntax error : identifier 'MenuMainHandle'
    .\Menus.c(200) : error C2059: syntax error : ';'
    .\Menus.c(201) : error C2061: syntax error : identifier 'MenuFileHandle'
    .\Menus.c(201) : error C2059: syntax error : ';'
    .\Menus.c(202) : error C2061: syntax error : identifier 'MenuEditHandle'
    .\Menus.c(202) : error C2059: syntax error : ';'
    .\Menus.c(203) : error C2061: syntax error : identifier 'MenuViewHandle'
    .\Menus.c(203) : error C2059: syntax error : ';'
    ... +22 similar errors
    .\Menus.c(245) : error C2143: syntax error : missing '{' before '*'
    .\Menus.c(245) : warning C4431: missing type specifier - int assumed. Note: C no longer supports default-int
    .\Menus.c(245) : warning C4218: nonstandard extension used : must specify at least a storage class or a type
    .\Menus.c(476) : error C2065: 'MenuMainHandle' : undeclared identifier
    .\Menus.c(476) : warning C4013: 'CreateMenu' undefined; assuming extern returning int
    .\Menus.c(479) : error C2065: 'MenuFileHandle' : undeclared identifier
    .\Menus.c(480) : error C2065: 'MenuEditHandle' : undeclared identifier
    .\Menus.c(481) : error C2065: 'MenuViewHandle' : undeclared identifier
    .\Menus.c(482) : error C2065: 'MenuObjectHandle' : undeclared identifier
    ... +10 similar errors
    .\Menus.c(522) : warning C4013: 'DestroyMenu' undefined; assuming extern returning int
    There's no way this could be happening. I checked all of my files and I don't see any extra } or missing { in them at all. Why it's not recognizing "CreateMenu" and "DestroyMenu" is completely baffling. The only thing I have above the following are a series of defines and comments:

    Code:
    HMENU MenuMainHandle;
    HMENU MenuFileHandle;
    HMENU MenuEditHandle;
    HMENU MenuViewHandle;
    ... +11 more similar ones
    Look at the order of my includes on the main file (using "stdafx.c" instead) and compare them to what I currently have (the "FILE *" is moved to menus which makes it after everything). It's like there's an extra } but there aren't any. I used find to count them.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mysterious Internet Explorer TCP connections to Microsoft webserver?
    By Sebastiani in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-13-2008, 01:30 PM
  2. mysterious shared memory
    By gandalf_bar in forum Linux Programming
    Replies: 4
    Last Post: 05-03-2004, 11:38 PM
  3. Mysterious fprintf problem
    By f97tosc in forum C Programming
    Replies: 9
    Last Post: 03-25-2003, 01:01 PM
  4. Mysterious crash on DestroyWindow()
    By Hunter2 in forum Game Programming
    Replies: 8
    Last Post: 02-03-2003, 08:03 PM
  5. Mysterious message from vVv
    By sean in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 06-08-2002, 04:11 PM

Tags for this Thread