Link to home
Start Free TrialLog in
Avatar of gavinpat
gavinpat

asked on

TClass, CClass, WClass ?!?

  I'm in the position of writing a moderately sized C++ project and I wan't to make sure that the classes that I declare won't clash with class names of the compiler.
   So Microsoft use the CClass naming covention, Borland use TClass. I want to know what naming conventions other major compilers (eg Watcom) use so that I can avoid them.
    I've been told that Borland strips the first character from all classnames on it's component pallette in Builder; can anyone confirm or deny this allegation. I assume there is a way of "overriding" this - what is it?
     Finally is there a way of grouping my header files so that I can make sure the right one is included when a file has a Borland or Microsoft namesake.

- OK so the last question was a bit of a red herring as the compiler will be sure to tell me in one way or the other if it is using Borland's tree.h file instead of my tree.h file and if I'd specified the path the problem wouldn't have arisen.
Anyway thanks to all, alexo get's the points for telling me the version numbers. Nietod would have got them if he had - he'll probably get them next time anyway.  Extended thanks to all.

PS Alexo you'll need to reply to get those points I think
Avatar of nietod
nietod

namespaces are the best way to prevent naming clashes.  The idea of prefixing names with a letter was developed before namespaces were introduced and is an imperfect solution.  (If it were a perfect solution, you wouldn't be asking this question...)  
I am afraid namespaces are not yet widely supported. In the mean while, you can use longer prefixes (2-3 letters), so the probablility of a name clash will be smaller.

As for your second question, do you mean something like the following?

#ifdef _MSC_VER
#include "ms_header.h"
#elif defined(__BORLANDC__)
#include "borland_header.h"
#elif defined (__WATCOM_CPLUSPLUS__)
#include "watcom_header.h"
#else
#error "unknown compiler"
#endif
Namespaces are supported by MSVC (verified in version 4.2) and Borland (verified in BC++ version 5.02)
Avatar of gavinpat

ASKER

Edited text of question
Edited text of question
gavinpat.  In the future you should post comments to your question rather than re-edtign the question.  It is a little easier to read and keeps a more chronological log of the discussion.  I mention this because Alexo may have missed your request for him to answer the question.  Try posting the request in a comment.
Come and get those points Alexo!

ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial