6

My team has been mandated to use a specific coding standard, and part of that standard is to use .cc as the suffix for C class implementation files (for sake of argument, it could have been .cxx, .c++, or any number of other suffixes which are not .cpp).

We're using the Eclipse CDT (C/C++ Development Toolkit) for development, however in the "New C++ Class" dialog, when you type in a class name as Classname, for example, it automatically names your Source file as Classname.cpp.

Sure, I could uncheck the "use default" checkbox and repair the suffix, but that's a few extra steps, and a lot to ask every Engineer on the large-ish project to remember to do each time they make a new C++ class.

I have been stumped, however, trying to find the option that allows one to specify the default suffix for C++ files in Eclipse CDT. Any Eclipse gurus know this one off hand?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Ogre Psalm33
  • 21,366
  • 16
  • 74
  • 92

4 Answers4

14

See Window > Preferences > C/C++ > Code Style > Name Style > Files > C++ Source File > Suffix

Sergey Prigogin
  • 384
  • 3
  • 5
  • 1
    Nice! Was this feature present in Eclipse 3.6? We're using Eclipse 3.7 with CDT 8.0 now, and I checked...sure enough, it was right where you said it was! – Ogre Psalm33 Feb 05 '13 at 18:49
  • And just as an FYI...I just checked. The feature is not present in Eclispe 3.6. – Ogre Psalm33 Feb 05 '13 at 18:53
2

I've digged Eclipse CDT code and found a solution:

append

nameStyle.cpp.source.suffix=.cc

to

<workspace location>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs

Here is how I did it:

  1. "Got started with CDT development", checked out org.eclipse.cdt.ui
  2. Opened src/org.eclipse.cdt.internal.ui.wizards.filewizard/NewSourceFileGenerator.java (actually I searched for the ".cpp" pattern and found it)
  3. "public static String generateHeaderFileNameFromClass(String className)" tells us about PreferenceConstants.NAME_STYLE_CPP_HEADER_PREFIX
  4. We jump to PreferenceConstants.java and obtain the IPreferencesService path: nameStyle.cpp.source.prefix
  5. This article nicely explains where the prefs are stored
markhor
  • 2,235
  • 21
  • 18
2

The bug mentioned by Ogre Psalm33 was fixed in 2013.

The location in Eclipse 4.4 is:

Window > Preferences > C/C++ > Code Style > Name Style > Files

Related: Make Eclipse treat .h file as C++?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • Nice to see the 3.7 fix made it over to 4.x. We're still on the 3.x line on my (very long duration) legacy project, but for up-to-date developers, this is exactly what you want. – Ogre Psalm33 Jun 11 '15 at 20:03
1

Answer: it currently can't be done in Eclipse 3.6 (Helios) with CDT 7.0.0. See Eclipse Bugzilla entry. Apparently it's logged as a bug/missing feature, but nobody's assigned to work on it.

Ogre Psalm33
  • 21,366
  • 16
  • 74
  • 92