Re: std::vector crash

From: Christian Holm Christensen <cholm_at_nbi.dk>
Date: Fri, 17 Aug 2007 17:17:15 +0200


Hi Axel,

On Fri, 2007-08-17 at 12:43 +0200, Axel Naumann wrote:
> Hi Ilya,

...

> Totally independent remark:
> type names should not start with an underscore in C(++).

Why not?! A valid identifier in C/C++ has the following form

        [_a-zA-Z][_a-zA-Z0-9]*

That is, a letter or an underscore, follow by zero or more letters, numbers, or underscores. You can even use UTF encoded identifiers if you like - the standard, I believe, is quite explicit about that.

In fact, GCC's libstdc++ uses underscores as the first character of data members. See for example "stdexcept":

  class logic_error : public exception
  {
    string _M_msg;

There's absolutely _nothing_ wrong with using underscores as the first character of an identifier in C++. Personally, I prefer an underscore over ROOT's "f", but that's my preference, and I have the freedom to choose that convention.

ROOT has, in my mind, some pretty weird conventions on this: For example, all classes (more or less) start with a `T' rather than live inside a `ROOT' name space, some class names are abbreviated beyond all recognition (TH1), and `modules' are differentiated by name rather than by structure (TGeo<XXX> should really be ROOT::Geometry::<XXX>, TG<YYY> should be ROOT::Gui::<YYY>).

The point is, that there's all sorts of coding and naming conventions out there, and you are free to choose what ever you like, for better or for worse.

BTW, using an underscore as the first character of a structure name is a _very_ common idiom in C. One then often finds a typedef from the structure name to the same name, but without the leading underscore:

  typedet struct _foo {
    ...
  } foo;

That means you can write some stuff shorter, like

  void bar(foo* f);

rather than

  void bar(struct _foo* f);

However, as structures are just like classes (except members are public by default) in C++, and the `class' or `struct' prefix is not needed, it does not make much sense to use this idiom in C++. Doing

  struct foo { ... };
  void bar(foo* f);

is perfectly legal C++ (but not legal C).  

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm_at_nbi.dk               Web:    www.nbi.dk/~cholm
 | |
Received on Fri Aug 17 2007 - 17:17:21 CEST

This archive was generated by hypermail 2.2.0 : Fri Aug 17 2007 - 23:50:02 CEST