Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C
why we are using a # before include(#include)or in front of preprocessors?_
Posted 23-Sep-12 19:48pm
Comments
Volynsky Alex at 24-Sep-12 11:45am
   
Please try to read following links:
http://en.wikipedia.org/wiki/Preprocessor_directive
http://www.tenouk.com/Module10.html
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Using the # character in C like languages is part of the language definition. Usually this symbol is used for any directives that are used by the preprocessor. I guess there is no special reason why the original creators of C used the # symbol.
Read this Wikepedia article for more information about the C preprocessor:
http://en.wikipedia.org/wiki/C_preprocessor[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Because the preprocessor must know which are its commands.
Using a 'special character' like # prevents name collisions with the compiler.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

It makes it easier for both humans and computers to recognize which lines are preprocessor directives if they all start that way (think about it, if you're going through looking for preprocessor commands, it will be a lot easier if every line you're looking for starts with #). I don't think there's a particular reason # was chosen, besides the fact that it isn't used anywhere else in the language (that I can think of). It might be related to the fact it's a comment in most Linux/Unix shell scripts.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In the C and C++ programming languages, an #include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the include directive. The addition of #include guards to a header file is one way to make that file idempotent.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 200
3 Zoltán Zörgő 149
4 BillWoodruff 120
0 OriginalGriff 7,610
1 DamithSL 5,559
2 Sergey Alexandrovich Kryukov 5,324
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100