LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2012, 12:06 PM   #1
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Rep: Reputation: Disabled
Beginning C programming- exceptions to whitespace irrelevant? include directive


New to programming. In several texts and online resources I have read that whitespace is irrelevant in C (except of course with strings).

Today I ran across the fact that my compiler choked on the following form of an include directive:

Code:
#include < stdio.h>
A space before or after the header filename produces a fatal compile error. I have never seen this mentioned (yet).

Any other exceptions to "whitespace irrelevant" you know of? I'm using Debian with current gcc.

Thanks,
Keith Ostertag
 
Old 02-01-2012, 12:33 PM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by keithostertag View Post
New to programming. In several texts and online resources I have read that whitespace is irrelevant in C (except of course with strings).
that's true, AFAIS.

Quote:
Originally Posted by keithostertag View Post
Code:
#include < stdio.h>
A space before or after the header filename produces a fatal compile error. I have never seen this mentioned (yet).
This is -strictly speaking- not a C issue. The directives starting with a hash sign are parsed by the preprocessor, which used to be a separate tool in earlier compiler designs. Today, it's usually integrated in the compiler. Yet the preprocessing is a pass of its own, formally.

Anyway ... In your example, the < and > characters are considered string delimiters, and so the contents they enclose is a string. Note that you may use quotes instead of the < > and then you wouldn't have seen this as an exeption, would you?
However, there is a difference between using quotes and angle brackets with #include. If you use angle brackets, the compiler searches for the included file in its pre-configured include directories. If you use quotes, it searches in the source file's directory first, and then in the include directories.

[X] Doc CPU
 
1 members found this post helpful.
Old 02-01-2012, 12:41 PM   #3
keithostertag
Member
 
Registered: Jul 2011
Location: Harrisburg, PA
Posts: 127

Original Poster
Rep: Reputation: Disabled
Thank you for an informative response!
 
Old 02-01-2012, 01:06 PM   #4
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
You might like the GNU C Preprocessor and the GNU C Reference Manual. For actual mastery you can get final draft standards free at www.open-std.org. Wrapping your head around the structure and detail of tho standards demands the kind of thinking that will serve you _very_ well professionally, but don't try them until you feel you have a real idea of what compilers and linkers and loaders do.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell programming : problem with directory name with whitespace papiseckfr Programming 2 05-17-2006 09:06 AM
Beginning programming mikeymorgan Programming 38 06-28-2005 07:59 AM
just beginning c programming mcd Programming 12 02-24-2005 05:06 PM
[Maybe redundant] main.cpp:1:18: warning: extra tokens at end of #include directive pycoucou Programming 2 10-26-2004 09:57 AM
%include directive in Kickstart configuration file deepika Linux - Newbie 0 07-24-2003 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration