is size_t always unsigned?

Yes. It’s usually defined as something like the following (on 32-bit systems): typedef unsigned int size_t; Reference: C++ Standard Section 18.1 defines size_t is in <cstddef> which is described in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an unsigned integral type of the result of the sizeof operator

Is auto_ptr deprecated?

UPDATE: This answer was written in 2010 and as anticipated std::auto_ptr has been deprecated. The advice is entirely valid. In C++0x std::auto_ptr will be deprecated in favor of std::unique_ptr. The choice of smart pointer will depend on your use case and your requirements, with std::unique_ptr with move semantics for single ownership that can be used … Read more

Why statements cannot appear at namespace scope?

The expression p++ which you’ve written is at namespace scope. It is forbidden by the grammer of namespace-body which is defined in §7.3.1/1 as: namespace-body:      declaration-seqopt which says the namespace-body can optionally contain only declaration. And p++ is surely not a declaration, it is an expression, therefore the Standard implicitly forbids it. The Standard might … Read more

Base pointer to array of derived objects

If you look at the expression p[1], p is a Base* (Base is a completely-defined type) and 1 is an int, so according to ISO/IEC 14882:2003 5.2.1 [expr.sub] this expression is valid and identical to *((p)+(1)). From 5.7 [expr.add] / 5, when an integer is added to a pointer, the result is only well defined … Read more

Are constant C expressions evaluated at compile time or at runtime?

Macros are simply textual substitution, so in your example writing TIMER_100_MS in a program is a fancy way of writing 32768 / 10. Therefore, the question is when the compiler would evaluate 32768 / 10, which is a constant integral expression. I don’t think the standard requires any particular behavior here (since run-time and compile-time … Read more

is it ok to specialize std::numeric_limits for user-defined number-like classes?

Short answer: Go ahead, nothing bad will happen. Long answer: The C++ standard extensively protects the ::std namespace in C++11 17.6.4.2.1, but specifically allows your case in paragraphs 1 and 2: The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std … Read more

tech