[Nfd-dev] size_t vs std::size_t

Davide Pesavento davide.pesavento at lip6.fr
Tue Jul 22 10:16:09 PDT 2014


On Tue, Jul 22, 2014 at 10:10 AM, Junxiao Shi
<shijunxiao at email.arizona.edu> wrote:
> Dear folks
>
> A question is raised in code review regarding whether we should use size_t
> or std::size_t in our code.
>
> According to answers in
> <http://stackoverflow.com/questions/5813700/difference-between-size-t-and-stdsize-t>:
>
> * std::size_t is in C++ standard, defined in <cstddef> header
> * size_t is from C standard, defined in <stddef.h> header
> * C++ standard requires, if an implementation defines size_t, it must be
> same as std::size_t
> * all major compilers define both size_t and std::size_t in <cstddef>
> * our code includes <cstddef>

Where? I see only <stddef.h> in ndn-cxx's common.hpp (which is
included by NFD's common.hpp). Should we switch to the C++ variant?

>
> Therefore, there is no functional difference between these two types.
>
> My opinion is: we should use size_t because it's more concise.

+1

> To fully support C++ standard, we should also add "using std::size_t"
> statement in common.hpp.

Yes, but only if we change ndn-cxx to include <cstddef> rather than <stddef.h>.

Thanks,
Davide



More information about the Nfd-dev mailing list