473,503 Members | 9,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why filename uniformity is important. *.c++ *.h++

I've mentioned a few times that the lack of standard filenames in C++ can be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.

Not infrequently, I want to work on code written with one tool in the other.
Well, Emacs thinks of *.h files as C rather than C++ headers, and thus goes
into C mode when they are opened. If I don't catch it, the code is
fromatted and highlighted differently than it would be in C++ mode. I
therefore use *.hh nameing when using Emacs (as well as *.cc, because I
like it better than *.cpp). OTOH KDevelop doesn't deal with *.hh (nore
*.cc) files well, preferring *.h (and *.cpp).

OK, so I spin up some bash to convert a directory from one form to the
other:

function kdev2emacs()
{
test -d old || mkdir old;

for f in *.h; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.h}.hh;
mv $f old;
done

for f in *.cpp; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.cpp}.cc;
mv $f old;
done
}

$ ls
main.cpp ring.cpp ring.h torus.cpp torus.h torusscene.cpp torusscene.h

$ grep \#include *[ph]
main.cpp:#include "torusscene.h"
....
torusscene.cpp:#include "torus.h"
torusscene.cpp:#include "torus.moc"

$ kdev2emacs

$ ls
main.cc old ring.cc ring.hh torus.cc torus.hh torusscene.cc
torusscene.hh
$ grep \#include *[ch]
main.cc:#include "torusscene.hh"
....
torusscene.cc:#include "torus.hh"
torusscene.cc:#include "torus.moc"

Cool! It works! ...

Whoops!
torusscene.cc:#include <Inventor/Qt/SoQt.hh>
torusscene.cc:#include <Inventor/Qt/viewers/SoQtExaminerViewer.hh>
torusscene.cc:#include <Inventor/SbBasic.hh>
torusscene.cc:#include <Inventor/fields/SoMFVec3f.hh>
torusscene.cc:#include <Inventor/nodes/SoSeparator.hh>
torusscene.cc:#include <Inventor/nodes/SoTransform.hh>
torusscene.cc:#include <Inventor/nodes/SoCoordinate3.hh>
torusscene.cc:#include <Inventor/nodes/SoQuadMesh.hh>
torusscene.cc:#include <Inventor/nodes/SoShapeHints.hh>

These aren't mine. I can't simply rename or symlink them.

And as I've already said, *.c++ and *.h++ is the One True Way.[*] http://www.gnu.org/software/emacs/emacs.html
[**] http://www.kdevelop.org
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #1
10 1884
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:1Z********************@speakeasy.net...
I've mentioned a few times that the lack of standard filenames in C++ can
be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.


I don't know about KDevelop, but in Emacs, you can indicate that a file is a
C++ file by putting a comment such as

// -*-C++-*-

near the beginning of the file. Then the file's name doesn't matter.
Jul 22 '05 #2
Andrew Koenig wrote:
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:1Z********************@speakeasy.net...
I've mentioned a few times that the lack of standard filenames in C++ can
be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.


I don't know about KDevelop, but in Emacs, you can indicate that a file is
a C++ file by putting a comment such as

// -*-C++-*-

near the beginning of the file. Then the file's name doesn't matter.


Yes. However, if I open code that was created in KDevelop, and I did not
make the conscious effort to add the Emacs mode specification, or I open
code written by someone else, I still have the problem. And even if the
code /does/ have the mode specification, the speedbar won't pick it up.

I ran into this when working with Open Scene Graph[*] which uses
extensionless headers. They have the Emacs mode specification, but speedbar
depends on filenames, and therefore will not show their headers. I've been
symlinking them, but that is an ugly kludge with problems.
[*]http://www.openscenegraph.org/
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #3

I myself use:

..cpp
..hpp
to emphasize that the language I'm dealing with is C++.
Hypothetically speaking, if I were to write C code (which I wouldn't), then
I'd call them:

..c
..h
-JKop
Jul 22 '05 #4
On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
<su******@setidava.kushan.aa> wrote:
And as I've already said, *.c++ and *.h++ is the One True Way.


I think some OSes can't take + characters in filenames. DOS? Remember,
C++ and DOS are still widely used together (DJGPP).

Tom
Jul 22 '05 #5
Tom Widmer posted:
On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
<su******@setidava.kushan.aa> wrote:
And as I've already said, *.c++ and *.h++ is the One True Way.


I think some OSes can't take + characters in filenames. DOS? Remember,
C++ and DOS are still widely used together (DJGPP).

Tom


Which is exactly why I prefer:

..cpp
..hpp

over:

..c++
..h++
I'll also limit the names to 8.3 (aaaaaaaa.123), when I'm writing code
files.

-JKop
Jul 22 '05 #6
Tom Widmer wrote:
On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
<su******@setidava.kushan.aa> wrote:
And as I've already said, *.c++ and *.h++ is the One True Way.
I think some OSes can't take + characters in filenames. DOS? Remember,


I try to forget.
C++ and DOS are still widely used together (DJGPP).

Ok, I'm curious. Who uses DOS these days for C++ development? Not the DOS
emulation in N(ew) T(estament) or Chi(X) Rho(P).

DJGPP?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #7
JKop wrote:
Which is exactly why I prefer:

.cpp
.hpp

over:

.c++
.h++
AFAIK, all recent Microsoft OS's support a + in a file name. I would have
to reboot to find out if XP does. The matching size of the extension is a
good thing. It makes it easier to grep in one shot.

I'll also limit the names to 8.3 (aaaaaaaa.123), when I'm writing code
files.


Guess which file holds the declaration for class sth::tmath::TensorIndex<>
sth/tmath/PowerOf.hh
sth/tmath/tmath_impl.hh
sth/tmath/Matrix.hh
sth/tmath/Vector.hh
sth/tmath/Space.hh
sth/tmath/Tensor.hh
sth/tmath/TensorIndex.hh

--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #8
On Fri, 15 Oct 2004 09:25:39 -0400, "Steven T. Hatton"
<su******@setidava.kushan.aa> wrote:
Tom Widmer wrote:
On Fri, 15 Oct 2004 00:08:23 -0400, "Steven T. Hatton"
<su******@setidava.kushan.aa> wrote:
And as I've already said, *.c++ and *.h++ is the One True Way.


I think some OSes can't take + characters in filenames. DOS? Remember,


I try to forget.
C++ and DOS are still widely used together (DJGPP).

Ok, I'm curious. Who uses DOS these days for C++ development? Not the DOS
emulation in N(ew) T(estament) or Chi(X) Rho(P).

DJGPP?


Google...

Tom
Jul 22 '05 #9
Steven T. Hatton wrote:
I've mentioned a few times that the lack of standard filenames in C++ can be
problematic. [...]


And I guess you just can't help it but mention it again...
Why don't you post this to a newsgroup for your OS, eh? It is only
relevant there. For all I know, there exists a system with a C++
compiler where files are identified by numbers and not names.
Jul 22 '05 #10

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:1Z********************@speakeasy.net...
And as I've already said, *.c++ and *.h++ is the One True Way.


Hmm. That must mean that everyone is doing it wrong. In almost all cases,
I see .cpp and .h as the extensions on the files I use, whether written
in-house or by a third party. I stick to that, because it's what everyone
else is using. Conformity as well as uniformity, you understand. :-)

-Howard
Jul 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3217
by: Shawn Wilson | last post by:
Hi, I've created a PHP file called filename.jpg. It outputs a JPG. I've set up a .htaccess file to force the filetype to PHP. The file is displayed in a page on a browser. I cannot get the...
11
3214
by: hokiegal99 | last post by:
How would I determine if a filename is greater than a certain number of characters and then truncate it to that number? For example a file named XXXXXXXXX.txt would become XXXXXX fname = files...
5
1281
by: Mr Newbie | last post by:
Now I know that VS2005 has master pages and web parts etc etc. However, at present I am forced to work with VS2003 so I have a couple of basic questions related to the subject matter for which I am...
3
1672
by: dick | last post by:
Hello, I want to encrypt a file with its filename. I can encrypt the file itself using the frame libraries. How can I now best hide the filename and extension? Within the file, ... ? I...
12
7968
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files...
4
2496
by: B Squared | last post by:
I'm trying to pass a filename (which is a jpeg image) to a php function / file so that it will display. I know that its simple to get PHP to display an image hardcoding in the filename. For...
2
1434
by: cygsoft | last post by:
Hi I have designed some Web Pages using Dreamweaver. The screens are looking fine when previewed with IE 6 browser. But when I view those in Netscape, the screens are totally collapsed. So can...
2
2260
by: MattGaff | last post by:
I have made an imagelist and populated it with a few images where the filename of each of the files is important. I can generate the random images in a PictureBox when I click a button. The code...
14
1471
by: Phil Stanton | last post by:
I have 1 FE database which can be linked to a number of BE databases. The BEs are all different Clubs e.g. Sailing Club, Yacht Club, Bridge Club, Family etc. Problem is if I change anything in...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.