Chic documentation
Houlder Technologies


Statements
Home
Features
Tutorial
Examples
FAQ
Reference
Download
Mailing list
Contact

Contents

Namespaces and classes

Namespaces and class definitions are moved to the header files. Inner classes remain inside their encapsulating class. Structs and unions are treated similarly to classes.

Forward declared classes are moved to the header file.

Variables

Member variables

Non-static member variables are moved directly to the header file. The way static variables in class scope are treated depends on whether they are of constant integral type or not. Since constant integral types may be used in constant expressions (e.g initializers or array ranges) their initializers are placed in the header file. The initializers of non-constant types and all non-integral types are placed in the implementation file.

Hic-file:
  class A
  {
    class B {};
    typedef short Short;
    enum Enum { E0, E1 };

    // Non-static.
    int i0;
    int const i1 = 1;

    // Static:

    // Non-const.
    static int i2 = 2;
    static B b0 = B();

    // Const integral.
    static int const i3 = 3;
    static Short const s0 = 0;
    static Enum const e0 = E0;

    // Const non-integral.
    static double const d0 = 0.0;
    static B const b1 = B();
  };
Header:
  class A
  {
    // ...
    class B {};
    typedef short Short;
    enum Enum { E0, E1 };

    // Non-static.
    int i0;
    int const i1 = 1;

    // Static:

    // Non-const.
    static int i2;
    static B b0;

    // Const integral.
    static int const i3 = 3;
    static Short const s0 = 0;
    static Enum const e0 = E0;

    // Const non-integral.
    static double const d0;
    static B const b1;
  };
Cc-file:
  int A::i2 = 2;
  A::B A::b0 = B();
  double const A::d0 = 0.0;
  A::B const A::b1 = B();

If not all include directives were followed the presence of typedefs or enumerators may prevent Chic from discover whether a variable is integral or not. It will then assume the type is non-integral.

The treatment of illegal constructs such as a const without an initializer or a non-static const with initializer at class scope is fairly unpredictable. However, Chic attempts to do something reasonable so that the compiler will later give the correct error message.

Variables in namespace scope

Variables in namespace scope are treated differently depending on whether they are constant or not. Constant types are entirely placed in the header file, whereas non-const types are forward declared in the header file and defined in the implementation file. This is in accordance with the rules of C++ that allow multiple inclusion of constant variables but not of non-const variables (constants have internal linkage while non-consts have external linkage). Forward declarations of variables are put directly into the header file, just like other forward declarations.

Hic-file:
  int i0;
  int i1 = 1;
  extern int i2;
  extern int i3 = 3;
  int const i4 = 4;
  extern int const i5;
  extern int const i6 = 6;
Header:
  extern int i0;
  extern int i1;
  extern int i2;
  extern int i3;
  int const i4 = 4;
  extern int const i5;
  extern int const i6 = 6;
Cc-file:
  int i0;
  int i1 = 1;
  extern int i3 = 3;

A variable declared extern "C" (or any other string) is treated similarly to an ordinary extern variable.

Don't use static variable in namespace scope. Static in this context is a deprecated feature of C++. In hic-files you should always use unnamed namespaces instead:

Hic-file:

  // Deprecated C++, don't use.
  // static int a;

  // Modern C++.
  namespace { int a; }
Header: <empty>

Cc-file:

  namespace { int a; }

Functions

Member functions and free functions are split in two. The return value and the function name of the definition are qualified. Inline function definitions and non-inline function definitions are moved to the ii-file and cc-file respectively.

Do not use static free functions. That's a deprecated feature of C++. Use unnamed namespaces instead.

Function forward declarations are moved to the header file.

Friend functions

Friend function declarations are moved to the header file.

Friend functions defined inside a class are left in the class regardless of whether they are declared inline or not.

Linkage directives

Extern blocks are moved to the header file. The contents are treated normally.

Unnamed namespace are moved to the cc-file and eventually wrapped in the same namespaces they were in the hic-file. The contents are not modified or used in any way.

Nested linkage directives are treated as in C++, i.e. the innermost decides the linkage and thus the destination.

Typedefs

Typedefs are moved to the header file. The contents of scopes which are marked as typedefs such as

  typedef struct { void f() {} } T0;
  typedef struct A { void g() {} } *T1;
are split if and only if the result would be legal C++. Otherwise the entire scope is put in the header file. In the example above only the second scope would be split as the first scope does not have an id.

Using directives

Using directives are moved to the header file.

Using declarations

Using declarations are moved to the header file.

Templates

Template classes are treated similarly to non-template classes.

Template functions and member functions of template classes are by default treated similarly to non-template functions. Non-exported template function definitions are put in the ii-file. Exported template function definitions are put in the cc-file.

Template function specializations

Template function specializations are moved to the cc-file.

Specializations of template member functions may be defined inside the class if and only if that class is not a template class or part of another template class. Note that this is not legal in conventional C++. Other specializations must be defined outside the class and be qualified with the class name. The following example summarizes:

Hic-file:
  namespace N
  {
    class C0
    {
      template <class T>
      void f(T) {}
      template <>
      void f(int) {}
    };

    template <class T>
    class C1
    {
      void g() {}
    };
    template <>
    void C1<int>::g() {}
  }
Header:
  namespace N
  {
    class C0
    {
      template <class T>
      void f(T);
    };

    template <class T>
    class C1
    {
      void g();
    };
  }
Ii-file:
  template <class T>
  void N::C0::f(T) {}
  template <class T>
  void N::C1<T>::g() {}
Cc-file:
  template <>
  void N::C0::f(int) {}
  template <>
  void N::C1<int>::g()
For additional control Chic provides parameters that affect the location of templates and of function definitions in general.

Template instantiations

Template instantiations are moved to the cc-file.

Macro directives

Macro directives are moved to the cc-file.





Home