ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't know which one is correct but in my Uni we were taught to use .cpp and .h for headers (no implementation is in headers except inline functions [limited use of inline functions], just plain declaration)
well surely it's bad to change convention within the same code.. if you're using cpp then surely you should have hpp headers... i'm sure it matters somehow! presumably mara's .C is capital? it has to be very bad practise to use .c for c++
Using capital C is ok if your code is only used on some *nix box, but it won't work on a windows box since path names are not case sensitive (*.c==*.C).
I didn't realize .C was used, and on second thought, it doesn't look that bad either.
However, I can't be that cruel to all the people with inferior OSes, that really have a yen for MY code!
I used .cpp, and reason is it was easiest to write and clearest to read.
But, I'm not sure will you get same results, but try this anyway:
1. Make some simple C++ program (something like 10 lines)
2. Name it first as program.cpp -> gcc ./program.cpp -o A
3. Then name source file as program2.c++ -> gcc ./program2.cpp -o A
4. Sources were identical, but is it just me or ARE programs compiled from .cpp ending heavier (more bits) than those of .c++ ending???
>Which one to use?
I stick to .cpp, and love it. When I moved from C to C++ (i.e from
structured to OOP, I felt very annoyed at having to name all the
file .cpp as against .c (.c seemed so easy). But gradually got used
to it.
>Which one do you prefer?
always .cpp. No question of .java or .anything or even .C. I love,
eat, breathe, shit cpp.
>Please state your reasons!
Not everything has reasons. I love BMW M3, but can't rationale.
>Please comment upon this important issue!
IMHO, it's not such an important issue, especially on *nix. In M$
windows (VC++), sometimes you have a requrement that your
files be named only .cpp or .cxx, but not in GNU C++.
Rather than wondering what *extentions* people use, I would
ask why kind of programming they do i.e whether OOP or
structured (C).
--Which one do you prefer?
I really don't have a preference, but I use "cpp" unless I have a good reason not to use it.
--Please state your reasons!
I write code for both Unix/Linux and Windows platforms and sometimes the same code file is used on both. The cpp extension is valid, by default, for both g++ on Linux/Unix and VC6 on Windows. If I used other systems or compilers, I might use another suffix if it was a default across all the systems being used.
Visual C++ generates cpp files and recognizes cpp files as C++ code by default. This can be changed, but is just another step in setting up a project.
GNU Make has builtin rules to compile cpp as C++ code, as well as cc and C. You can add rules for other extensions, but it would add lines to the Makefile.
--Please comment upon this important issue!
Lazy me. One less thing to remember to do when setting up a Makfile or MSVC project.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.