Since this answer still gets voted up, I want to point out that you should almost never need to look in the header files. If you want to write reliable code, you're much better served by looking in the standard. So, the answer to "where can I find the complete definition of off_t
" is "in a standard, rather than a header file". Following the standard means that your code will work today and tomorrow, on any machine.
In this case, off_t
isn't defined by the C standard. It's part of the POSIX standard, which you can browse here.
Unfortunately, off_t
isn't very rigorously defined. All I could find to define it is on the page on sys/types.h
:
blkcnt_t
and off_t
shall be signed integer types.
This means that you can't be sure how big it is. If you're using GNU C, you can use the instructions in the answer below to ensure that it's 64 bits. Or better, you can convert to a standards defined size before putting it on the wire. This is how projects like Google's Protocol Buffers work (although that is a C++ project).
For completeness here's the answer to "which header file defines off_t
?":
On my machine (and most machines using glibc) you'll find the definition in bits/types.h
(as a comment says at the top, never directly include this file), but it's obscured a bit in a bunch of macros. An alternative to trying to unravel them is to look at the preprocessor output:
#include <stdio.h>
#include <sys/types.h>
int main(void) {
off_t blah;
return 0;
}
And then:
$ gcc -E sizes.c | grep __off_t
typedef long int __off_t;
....
However, if you want to know the size of something, you can always use the sizeof()
operator.
Edit: Just saw the part of your question about the __
. This answer has a good discussion. The key point is that names starting with __
are reserved for the implementation (so you shouldn't start your own definitions with __
).
__
is reserved for use by the implementation (unless the standard defines a meaning for it, as in__func__
or__FILE__
). The level of indirection lets the implementation define its own type__off_t
without interfering with anything you can legitimately do. The platform-specific bits of the headers can then be better hidden (so a single copy of the source code can handle 32-bit and 64-bit compilations on a single machine, for example). Reading standard headers is a major chore because there are so many interlinked definitions. – Godthaab