Skip to content

C and CPP

Ali Al-Ramadan edited this page Nov 14, 2026 · 2 revisions

The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in C and C++ as in every language of Stereocode. The section Data Members and Calls of the method stereotypes states the conventions by which Stereocode determines the facts of these rules in every language. This page gives the forms that these facts take in C and C++, the built-in lists that Stereocode reads for C and C++, and one labeled example of each stereotype.

Language Facts

Classes and functions

  • Stereocode reads a C unit as a C++ unit. A C unit thus holds free functions, structs, and unions, which get their stereotypes with the options -f, -t, and -u.
  • A method defined outside its class belongs to the class that its qualified name names, such as Surface::draw. Where the class sits in a namespace, a using namespace directive before the definition reaches the class, provided that exactly one class of that name fits. Where every method of that name in the class is static, the definition is a static method, also where its parameter types differ in their text from those of the declaration.
  • A method that several #if alternatives define counts once in the class stereotypes, with the stereotypes of its first definition.

Data members

  • A method reaches its object through this or *this. A name without this-> may also name a data member of the class.
  • A const method changes only mutable data members. Such a method is a set when it changes one data member and a command only when it changes more than one data member or the whole object.
  • Inside a local class, this names the object of that class. this->x thus names the member x of the local class and counts as a local variable of the enclosing method. A call through this is a call on an object other than the object of that method, as is a call without an object of a method that the local class defines.

Types and variables

  • A parameter shares its object with the caller when it is a reference, a pointer, or an array to an object that is not const.
  • A function pointer, such as bool (*filter)(int);, declares a data member, a parameter, or a local variable, never a method.
  • Stereocode resolves an alias of the type of a data member, such as using ItemPtr = std::unique_ptr<Item>; or typedef Item* ItemPtr;, to the aliased type. A standard smart pointer, such as std::unique_ptr<Item>, counts by the type Item of the object that it manages.

Calls

  • A call qualified with the name of the own type or of a parent type, such as Base::draw(), calls a method of the object itself. A member alias of the type or of a parent, such as typedef StaticDialog MyBaseClass;, qualifies such a call as the name of the parent does. A call qualified with the name of any other type remains a call of a free function.
  • Beyond the two cases of the section Data Members and Calls, a call to the object itself whose method no type of the archive defines reads the object where the call stands in a const method of a type with a parent outside the archive, since a const method changes only mutable data members.
  • A binary operator whose left operand is *this, such as *this == other, calls the operator function of the type or a free function. << and >> after a stream or after a variable of a class of the archive are calls on that variable. Each operand that >> extracts into is written, while a shift of a number counts as no call.
  • A method creates an object with new, also without an argument list, as in new Matrix. std::make_unique and std::make_shared count as new.

Built-in Lists

Stereocode reads four built-in lists for C and C++. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [C++], as the README states. Each list below opens with a click.

Primitive types (36 entries)

A type of this list makes no method a collaborator and no return type of a factory.

bool, byte, char, char16_t, char32_t, char8_t, double, float, int, int16_t, int32_t, int64_t, int8_t, long, longdouble, longint, longlong, longlongint, ptrdiff_t, short, shortint, size_t, size_type, string, string_view, u16string, u32string, u8string, uint16_t, uint32_t, uint64_t, uint8_t, void, wchar_t, wstring, wstring_view

Ignored calls (3 entries)

The rules ignore a call of these names, also after a qualifier, as std::exit for exit.

abort, assert, exit

Specifiers and containers (58 entries)

Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....

&, &&, ::const_iterator, ::iterator, <, >, \*, __cdecl, __clrcall, __fastcall, __stdcall, __thiscall, __vectorcall, _Noreturn, _Thread_local, APIENTRY, array, CALLBACK, const, constexpr, deque, explicit, extern, forward_list, friend, inline, list, map, multimap, multiset, mutable, pair, PASCAL, priority_queue, private, protected, public, queue, register, restrict, set, signed, span, stack, static, STDAPICALLTYPE, STDMETHODCALLTYPE, thread_local, unordered_map, unordered_multimap, unordered_multiset, unordered_set, unsigned, vector, virtual, volatile, WINAPI, WINAPIV

Query methods (7 entries)

A call of these methods only reads the variable that the call is on.

c_str, capacity, count, empty, length, max_size, size

Examples

Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in C and C++.

Methods

Stereotype Stereotypes of the element Declaration
get get int getPosition() const { return position; }
predicate predicate bool full() const { return size() >= limit; }
property property double Meter::half(Ratio r) { return r / 2; }
void-accessor void-accessor inline void visible_cells(int& r1, int& r2, int& c1, int& c2)
set set void setCount(int count) { m_count = count; }
command command void setFirst(int x) { m_items.front() = x; }
non-void-command non-void-command int padded() { return width("a", "b"); }
factory factory collaborator stateless Widget* make() const { return new Widget(); }
collaborator collaborator void DisplayController::fixLogIfBinned ( const PlotterBase* plotter, DataRep*...
controller controller void show(std::ostream& out) const { out << value; }
wrapper wrapper void copyThroughPointer() { parts()->b = b; }
incidental incidental const char* name() const { return "plugin"; }
stateless stateless int* cell() const { return new int; }
empty empty void close() { /* nothing to release */ }
constructor constructor Point(int x, const Point* parent) : m_x(x) {}
copy-constructor copy-constructor Point(const Point& other) : m_x(other.m_x) {}
destructor destructor ~Matrix() { delete[] m_cells; }
unclassified unclassified int Dot::madeOutOfClass() { return s_made; }

TABLE 1. Examples of the method stereotypes in C and C++.

Free functions

Stereotype Stereotypes of the element Declaration
main main int main(void) { bump(); show(twice(zero())); return 0; }
predicate predicate bool isEven(int value) { return value % 2 == 0; }
property property int square(int value) { return value * value; }
global-command global-command void addCalls(int count) { g_calls += count; }
command command void set_x(struct point* p, int x) { p->x = x; }
factory property factory Widget* makeWidget(int style) { Widget* widget = new Widget(style); return wi...
literal literal static int zero(void) { return 0; }
wrapper wrapper void resetCopy(Widget widget) { widget.reset(); }
empty empty void noop(int value) { }
unclassified unclassified static int madeInClass() { return s_made; }

TABLE 2. Examples of the free-function stereotypes in C and C++, which the option -f assigns.

Types

Stereotype Stereotypes of the element Declaration
boundary boundary class Exporter
commander commander data-class small-class class Leaf : public Mid { public:
controller controller class Spooler
data-class data-class class Point
data-provider data-provider class Circle
data-struct data-provider data-struct small-struct struct Size { int width;
data-union data-provider data-union small-union typedef union
degenerate factory controller lazy-class degenerate class Factory100
empty empty union value { int i; float f; };
entity entity class Surface
factory factory controller class WidgetFactory
large-class large-class class Box
large-struct large-struct struct Frame
large-union large-union union Cell
lazy-class lazy-class class Settings
lazy-struct lazy-struct struct Slot
lazy-union lazy-union union Bits
minimal-entity minimal-entity class Point
pure-controller pure-controller class Dispatcher
small-class small-class class Counter
small-struct data-provider small-struct struct Pixel : public Point
small-union data-provider data-union small-union typedef union
unclassified unclassified class Large22

TABLE 3. Examples of the class stereotypes in C and C++, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.

Clone this wiki locally