Questions tagged [c++03]

C++03 is an older revision of the C++ standard. The more recent revisions, C++11 and the current C++14, are still being adopted.

In 2003, the C++ Committee responded to multiple problems that were reported with , and revised it accordingly. The changed language was dubbed C++03.

Though and more recently have superseded C++03, many compilers do not yet fully support the new standard. As a result, C++03 is still the default language standard used. Additionally, while the differences between C++98 and C++03 were primarily semantic, the C++11 standard added many new language-level features resulting in a greater impact to not only the compiler authors but to C++ programmers as well.

Please tag questions about C++03 with the c++ tag, along with the c++03 tag.

786 questions
301
votes
7 answers

Can C++ code be valid in both C++03 and C++11 but do different things?

Is it possible for C++ code to conform to both the C++03 standard and the C++11 standard, but do different things depending on under which standard it is being compiled?
Erik Sjölund
  • 9,109
  • 7
  • 34
  • 60
179
votes
6 answers

Can virtual functions have default parameters?

If I declare a base class (or interface class) and specify a default value for one or more of its parameters, do the derived classes have to specify the same defaults and if not, which defaults will manifest in the derived classes? Addendum: I'm…
Arnold Spence
  • 20,892
  • 7
  • 69
  • 66
130
votes
9 answers

Purpose of Trigraph sequences in C++?

According to C++'03 Standard 2.3/1: Before any other processing takes place, each occurrence of one of the following sequences of three characters (“trigraph sequences”) is replaced by the single character indicated in Table 1.…
Kirill V. Lyadvinsky
  • 89,955
  • 22
  • 127
  • 208
116
votes
8 answers

What differences, if any, between C++03 and C++11 can be detected at run-time?

It is possible to write a function, which, when compiled with a C compiler will return 0, and when compiled with a C++ compiler, will return 1 (the trivial sulution with #ifdef __cplusplus is not interesting). For example: int isCPP() { return…
Armen Tsirunyan
  • 120,726
  • 52
  • 304
  • 418
92
votes
3 answers

Default, value and zero initialization mess

I am very confused about value- & default- & zero-initialization. and especially when they kick in for the different standards C++03 and C++11 (and C++14). I am quoting and trying to extend a really good answer Value-/Default-/Zero- Init C++98 and…
Gabriel
  • 7,477
  • 5
  • 47
  • 87
85
votes
10 answers

Is there any reason to use the 'auto' keyword in C++03?

Note this question was originally posted in 2009, before C++11 was ratified and before the meaning of the auto keyword was drastically changed. The answers provided pertain only to the C++03 meaning of auto -- that being a storage class specified…
Carson Myers
  • 34,352
  • 35
  • 118
  • 164
82
votes
12 answers

How can I pass a class member function as a callback?

I'm using an API that requires me to pass a function pointer as a callback. I'm trying to use this API from my class but I'm getting compilation errors. Here is what I did from my…
ofer
  • 3,905
  • 7
  • 34
  • 38
78
votes
10 answers

initialize a const array in a class initializer in C++

I have the following class in C++: class a { const int b[2]; // other stuff follows // and here's the constructor a(void); } The question is, how do I initialize b in the initialization list, given that I can't initialize it inside…
Nathan Fellman
  • 108,984
  • 95
  • 246
  • 308
67
votes
2 answers

What are the differences between C-like, constructor, and uniform initialization?

To the best of my knowledge, there are three ways to initialize a variable in C++. int x = 0; // C-like initialization int x (0); // Constructor initialization int x {0}; // Uniform initialization The uniform initialization was brought on…
dayuloli
  • 13,791
  • 13
  • 58
  • 103
53
votes
3 answers

error: anachronistic old-style base class initializer

The following code produces the subsequent compilation error on all versions of GCC that I've tried, in C++98, C++11 and C++14 modes: struct T { T(void* x) : (x) {} }; // main.cpp: In constructor 'T::T(void*)': // main.cpp:3:18: error:…
Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
45
votes
11 answers

Which Typesafe Enum in C++ Are You Using?

It is common knowledge that built-in enums in C++ are not typesafe. I was wondering which classes implementing typesafe enums are used out there... I myself use the following "bicycle", but it is somewhat verbose and limited: typesafeenum.h: struct…
Alex Jenter
  • 4,112
  • 3
  • 33
  • 59
39
votes
6 answers

Does "&s[0]" point to contiguous characters in a std::string?

I'm doing some maintenance work and ran across something like the following: std::string s; s.resize( strLength ); // strLength is a size_t with the length of a C string in it. memcpy( &s[0], str, strLength ); I know using &s[0] would be safe…
paxos1977
  • 135,245
  • 26
  • 85
  • 125
36
votes
7 answers

What is the C++03 memory model for concurrency?

What is the memory model for concurrency in C++03? (And, does C++11 change the memory model to support concurrency better?)
yesraaj
  • 42,284
  • 65
  • 185
  • 246
35
votes
6 answers

Is value of x*f(x) unspecified if f modifies x?

I've looked at a bunch of questions regarding sequence points, and haven't been able to figure out if the order of evaluation for x*f(x) is guaranteed if f modifies x, and is this different for f(x)*x. Consider this code: #include int…
Navin
  • 1,231
  • 9
  • 16
32
votes
3 answers

Union initialization in C++ and C

I have built a working C library, that uses constants, in header files defined as typedef struct Y { union { struct bit_field bits; uint8_t raw[4]; } X; } CardInfo; static const CardInfo Y_CONSTANT = { .raw = {0, 0, 0, 0 } }; I know…
Alexander Oh
  • 20,413
  • 12
  • 65
  • 70
1
2 3
52 53