Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>std::size_t n = sizeof( long ); </code></pre> <p>Actually, you haven't asked what specifically seems to be a bad practice int the above. Use of size_t, qualification with std namespace,... </p> <p>As the C++ Standard says (18.1), size_t is a type defined in the standard header . I'd suggest to drop any thoughts and impressions about possible inheritance from C language. C++ is a separate and different language and it's better to consider it as such. It has its own standard library and all elements of C++ Standard Library are defined within namespace std. However, it is possible to use elements of C Standard Library in C++ program.</p> <p>I'd consider including as a dirty hack. The C++ Standard states that the content of headers is the same or based on corresponding headers from the C Standard Library, but in number of cases, changes have been applied. In other words, it's not a direct copy &amp; paste of C headers into C++ headers. </p> <p>size_t is not a built-in type in C++. It is a type defined to specify what kind of integral type is used as a return type of sizeof() operator, because an actual return type of sizeof() is implementation defined, so the C++ Standard unifies by defining size_t.</p> <blockquote> <p>would the following program (with no includes) be expected to compile on all C++ compilers?</p> <pre><code>size_t foo() { return sizeof( long ); } </code></pre> </blockquote> <p>The C++ Standard says (1.4):</p> <p><em>The names defined in the library have namespace scope (7.3). A C ++ translation unit (2.1) obtains access to these names by including the appropriate standard library header (16.2).</em></p> <p>The size_t is a name defined within std namespace, so every program that uses this name should include corresponding header, in this case.</p> <p>Next, the 3.7.3 chapter says:</p> <p><em>However, referring to std, std::bad_alloc, and std::size_t is ill-formed unless the name has been declared by including the appropriate header.</em></p> <p>Given that, program using size_t but not including header is ill-formed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload