View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1bluepig.man  Members

Posted 01 October 2013 - 08:58 AM

Hey,everyone. Today, l try write some code but without include any header file, but this code run well. In my opinion, if we want use something in c++ we need to include it's header file into our program. But why these keyword no need to include any header file ?

this the code:

class a
{
public:
int d;
int b;
private:
};

struct B
{
double c;
};

int A( const int &a, const double &b )
{
int justTest = 5;
int aa = a;
int bb = b;
return bb;
}

union MyUnion
{
int a;
int b;
struct c
{
};
};

int main()
{
a in;
in.d = 0;
in.d -= 5;
in.b = 6;
in.d -= in.b;

return 0;
}



Edited by bluepig.man, 03 October 2013 - 08:46 PM.

### #2jotak  Members

Posted 01 October 2013 - 09:36 AM

in this example you only use language native elements, without referring to any external function, type or class. That's why you d'ont have to include anything there. Just add somewhere

std::string s = "foo";

and you'll get an error because of missing headers.

### #3Cosmic314  Members

Posted 01 October 2013 - 09:46 AM

POPULAR

If I understand your question correctly, you're asking why the keywords of C++ do not need a header file.

Simply, they are a part of the language.  A compiler / parser is essentially hard-coded with the rules it needs to understand what keywords are, and what it is supposed to do with them.  Several international C++ standards exist which give precise definitions, depending on the version of C++ you're using.

While it might be possible for a tool to construct a language from a set of rules, such as the keywords, you would have to require that tool to have certain rules to understand those definitions.  At some point a tool must have some set of basic definitions for it to do its job.  And that's what keywords partially represent -- an internal skeleton that guides the parsing / compiling processes to choose the appropriate rules when translating your code.

### #4bluepig.man  Members

Posted 01 October 2013 - 07:13 PM

If I understand your question correctly, you're asking why the keywords of C++ do not need a header file.

Simply, they are a part of the language.  A compiler / parser is essentially hard-coded with the rules it needs to understand what keywords are, and what it is supposed to do with them.  Several international C++ standards exist which give precise definitions, depending on the version of C++ you're using.

While it might be possible for a tool to construct a language from a set of rules, such as the keywords, you would have to require that tool to have certain rules to understand those definitions.  At some point a tool must have some set of basic definitions for it to do its job.  And that's what keywords partially represent -- an internal skeleton that guides the parsing / compiling processes to choose the appropriate rules when translating your code.

Nice answer!  Before ask this question, l think if we want use something from language we must include some header file,but yesterdayl try to remove any header in my source file,then no error is reported.  This break my cognitive.  Your answer is very nice for me, thanks.

Edited by bluepig.man, 01 October 2013 - 07:16 PM.

### #5Xai  Members

Posted 01 October 2013 - 11:03 PM

You may wonder why / how the language designers decide what goes in the language as a "keyword" and / or "part of the core language", and what goes in the language as part of the "standard library" / aka requiring "#includes".

The normal short answer is - the language core is usually the smallest part reasonable, that can be used to write / reference the rest - they put nearly everything they can into the "standard library" instead of the language core ... but obviously if nothing is in the language itself, you couldn't do anything at all - so a certain subset of features needs to exist at a basic level, to even support the concept of writing basic code, and referencing and using already written code.

And as in Cosmic's answer ... it also includes whatever set of "rules" are needed so that the compiler / parser can just divide and understand the program's structure and content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.