DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: A question of style

  1. #1
    Join Date
    Oct 2007
    Posts
    369

    A question of style

    When, in C++, is it preferred to use <c...> instead of <....h>?
    Along with that, when can we assume <c...> will work? Just the standard c libraries?

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    It's more than a mere style issue. It's an issue of correct C++ code. In standard C++, all standard headers (including those of C) must begin with <c.. and end with >, without the .h extension. Using C-style headers is deprecated, and in many cases will not compile.
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    to me, a file has an extension that tells the reader what that file does. I find that to be one of the top 10 most annoying things in unix, are files with no extension. Following that idea, a user made include file should have a .h or .hpp extension so you can open it without having to explain for the grillionth time to the OS what program should open it. I also believe that windows is correct in asking what program to use because the file has no type. Even if you assume that typeless files are text, my text editor and code editor are not at all the same, so I would still have a problem.

    Hopefully, the powers that be will not decide to force typeless files on us, but there are other nonsense rules that cater to OS oddities like the blank end of line on every source file.

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    The question is not whether header should have the .h extension. User defined headers can stick to the user's own naming conventions, OS whims and compiler vagaries. The .h-less convention applies only to standard headers, and the rationale behind it (not that I endorse it) is that 1) some file systems have no extensions so there's no point in forcing extensions in the standard itself 2)some C header clash with C++ headers, string.h vs string, complex.h and complex etc. 3) the header file doesn't really have to be a physical file. Theoretically at least, it could be precompiled, encrypted data, a collection of several physical files, a temporary virtual file, etc. so forcing it to have a .h extension is an imposition. Anyway, the standard was changed more than 10 years ago so today this debate is pretty much ancient history. We're stuck with the <xxx> notation, at least in standard header files.
    Danny Kalev

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    Right, the built in ones are fine. Just covering the user ones... some places will tell you to do no type on user files (one big library that is hosed up because of this is openscenegraph -- it will barely compile).

  6. #6
    Join Date
    Oct 2007
    Posts
    369
    I guess I'm being obtuse, but I'm trying to figure out the definition of "standard header". I understand <cstdio>, but I didn't expect to use <csignal>.
    Are the "standard" ones the system libraries that aren't in subdirectories (like sys)?

  7. #7
    Join Date
    Nov 2003
    Posts
    4,118
    standard headers are those that are defined by the C++ standard, and they also include the standard header of C94, with a modified name. Thus C's <signal.h> is <csignal> etc. You simply have to look at the standard to tell which libraries and headers it defines.
    Danny Kalev

Similar Threads

  1. DotNetBar Suite 3.0 with Office 2003 style released
    By DevComponents in forum dotnet.announcements
    Replies: 0
    Last Post: 04-20-2003, 07:44 PM
  2. Display one record at a time!
    By ASP learner in forum ASP.NET
    Replies: 5
    Last Post: 10-08-2002, 07:17 PM
  3. question on best programming option
    By James in forum .NET
    Replies: 2
    Last Post: 03-28-2002, 08:14 AM
  4. beginner question: autonumber style field
    By Zack in forum Database
    Replies: 2
    Last Post: 10-27-2001, 10:59 AM
  5. Replies: 0
    Last Post: 06-21-2001, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center