Xcode #include strangeness

Posts: 321
Joined: 2004.10
Post: #1
I've got one file where I've put all my user defined types
into. It is named TypeDefs.h

typedef int myType; // one of many user types.

Source File: MySource.cpp

#include "TypeDefs.h"

myType heyThere; //compiler error: myType does not name a type.


It's so simple, that I think something very subtle is going on.

I've got many other source files which #include the TypeDefs.h file
with no problems whatsoever. I even just copied and pasted the
typedef directly into the Source file and then the compile works fine.

I'm thinking that Xcode for some reason is simpling not #including the
header file TypeDefs.h. Maybe I've turned off including without
realizing it? Is there a way within Xcode to verify that TypeDefs.h is
being included?
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #2
Try putting #pragma once at the top of your header. It might work. Wink
Quote this message in a reply
Posts: 321
Joined: 2004.10
Post: #3
Should typedefs go into .h header files or .cpp files? Looking at the typedef statement, lets
take a real simple example:

typedef int Integer;

There is no memory allocated at this time, so that makes it a declaration; Therefore
it should go in the .h file. Right?
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #4
Questions like that show a fundamental misunderstanding of how "headers" work.

Use the "Preprocess" command in Xcode (or the -E flag to gcc) to see the source that's making it to the compiler. Hopefully that should clear up your understanding.
Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #5
Besides that being a pretty pointless declaration, the rule is that public declarations (the typedefs and prototypes you want to use in other modules) go into the header, all the private stuff and definitions go into the implementation file.

Also, note that #pragma once is sort of deprecated (i use it, though), but you can also use
PHP Code:
#ifndef __MYFILE_H__
#define __MYFILE_H__
/*code goes here*/
as a "header guard".
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  StorageRoom - Include content in your games sashthebash 0 3,491 Jun 13, 2011 05:39 AM
Last Post: sashthebash
  #include <ft2build.h> BBBert 4 12,643 Apr 7, 2008 09:33 AM
Last Post: BBBert
  Newbie problem XCode Include files BBBert 1 5,481 Mar 17, 2008 03:46 PM
Last Post: OneSadCookie
  Fixing Include Paths vbuser1338 4 4,552 May 28, 2006 05:15 PM
Last Post: vbuser1338
  3 line OpenGL strangeness....? WhatMeWorry 1 4,049 Jul 2, 2005 07:15 PM
Last Post: OneSadCookie