Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


about keyword and include


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.

  • You cannot reply to this topic
4 replies to this topic

#1 bluepig.man   Members   -  Reputation: 419

Like
0Likes
Like

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 ?

If they aren't in header file, where they are? l tried to google ,but just can't find the answer. so please help. Thanks.

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
	{
		double ad;
	};
};

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.


Sponsor:

#2 jotak   Members   -  Reputation: 156

Like
0Likes
Like

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.



#3 Cosmic314   Members   -  Reputation: 1262

Like
5Likes
Like

Posted 01 October 2013 - 09:46 AM

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.



#4 bluepig.man   Members   -  Reputation: 419

Like
0Likes
Like

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.


#5 Xai   Crossbones+   -  Reputation: 1459

Like
1Likes
Like

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.



PARTNERS