Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

C++ including linux/types.h for size_t

I am trying to create a C++ wrapper (adding object orientation) around a C library (of which I am the author, i.e. I can apply changes there if needed). The C library defines some structs that make use of size_t as defined in linux/types.h since it interfaces with the kernel.

I am now trying to include the header of the C library (that defines the struct) in the sources of my attempt at a C++ library. However, if I do so, the compiler tells me that

size_t does not name a type

What is the correct way to get access to size_t from linux/types.h in C++?

P.S.: The header file contains a #ifdef _cplusplus extern "C" { #endif block

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't include kernel headers in userspace.

As stated in the C and C++ standards, size_t is defined in <stddef.h> (and for C++, <cstddef> defines std::size_t).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...