472,101 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

how to create header files in c/c++

hi, i m sourabh....... Can any1 tell me how to create a header file in c/c++
Oct 4 '08 #1
10 1699
JosAH
11,448 Expert 8TB
Simply create a text file with the extension .h and voila.

kind regards,

Jos
Oct 4 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
The text file doesn't even need the .h you just need to #include the text file in your source file.
Oct 4 '08 #3
Tassos Souris
152 100+
Exactly what the above guys said...

A typical example of a header file named Example.h is:
Expand|Select|Wrap|Line Numbers
  1. #ifndef EXAMPLE_H
  2. #define EXAMPLE_H
  3.  
  4. /* make definitions, declarations here... */
  5.  
  6. #endif /* EXAMPLE_H */
  7.  
Note that if you want to be strictly ANSI the above code is wrong!!! Visual Studio gives an error and gcc a warning. And the reason is the last comment...
Oct 5 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Note that if you want to be strictly ANSI the above code is wrong!!! Visual Studio gives an error and gcc a warning. And the reason is the last comment...
I'll bite. My Visual Studio sees no error.
Oct 5 '08 #5
Tassos Souris
152 100+
I'll bite. My Visual Studio sees no error.
Visual Studio gives an error as i said only with ANSI. You must put the /Za flag.

Specifically, the error is:
Expand|Select|Wrap|Line Numbers
  1. fatal error C1004: unexpected end-of-file found
  2.  
and that is because the logical source does not end with a new-line.. something like that..
Oct 5 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
Yes, the file must end with a null record. That is, enter-key only.
I don't know exactly what the ANSI standard says about this.
Oct 5 '08 #7
thats interesting to know..
thanks ...
Oct 6 '08 #8
JosAH
11,448 Expert 8TB
Yes, the file must end with a null record. That is, enter-key only.
I don't know exactly what the ANSI standard says about this.
The C99 Standard:

5.1.1.2. Environment

A source file that is not empty
shall end in a new-line character, which shall not be
immediately preceded by a backslash character before
any such splicing takes place.
By 'splicing' they mean the trailing backslash immediately followed by a new-line
character which concatenates two physical lines.

kind regards,

Jos
Oct 6 '08 #9
Tassos Souris
152 100+
I actually thought this was a bug in Visual Studio 2008 and asked a friend to send a bug report; the answer we got amazed us!!! :-P
Oct 6 '08 #10
Banfa
9,065 Expert Mod 8TB
I worked on a multi-platform project once where a new platform was introduced and its compiler produced an error where source files did not end in new-line. The compilers on the 3 existing platforms did not produce an error or even a warning in this case so lots of the code files did not end in a new-line.

Some lucky person (not me) got the job of adding a new-line to the end of all the (several 100) source files.
Oct 6 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by matthurne | last post: by
18 posts views Thread by John Smith | last post: by
5 posts views Thread by Michael Sperlle | last post: by
1 post views Thread by greg | last post: by
15 posts views Thread by lxyone | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.