12

How come there's no man page for the sizeof C function?

$ man 3 sizeof
No manual entry for sizeof in section 3

$ man sizeof
No manual entry for sizeof

I do see man pages for other C functions like malloc if I run man 3 malloc and similar commands, but nothing for sizeof.

1
  • why do you want to see Linux man page for a C thing? Unless it's a POSIX-related thing, reading from a standard document is better
    – phuclv
    Commented Mar 21, 2017 at 14:05

2 Answers 2

10

sizeof isn't a function. it's an operator: http://en.wikipedia.org/wiki/Sizeof

4
  • 1
    Is operator another word for macro? What does operator exactly mean? Commented May 14, 2014 at 17:10
  • 1
    No. A macro is some text (not reserved word, nor operator, nor function) interpreted by the precompiler and expanded into something that can be compiled. Operators look like functions, but they are part of the language itself. Functions usually are part of a library. For a detailed explanation read: en.wikipedia.org/wiki/Operator_(computer_programming)
    – drkblog
    Commented May 14, 2014 at 20:57
  • Thanks. Last question: Is there an official documentation for operators like this? Commented May 14, 2014 at 20:59
  • 5
    Yes. The C language specification: open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf - Check section 6.5.x
    – drkblog
    Commented May 14, 2014 at 21:03
3

You can use man -wK 'sizeof' | sort -u to find the articles that contain sizeof, but that'll return a lot of results. However notice that every article about something will have that thing as a bareword surrounded by spaces, we'll search for the article like this zgrep -P '\ssizeof\s' /usr/share/man/man3/*. But searching in section 3 doesn't give any useful information, so I'll search in section 7

$ zgrep -P '\ssizeof\s' /usr/share/man/man7/*
/usr/share/man/man7/inotify.7.gz:        len = read(fd, buf, sizeof buf);
/usr/share/man/man7/operator.7.gz:! ~ ++ \-\- + \- (type) * & sizeof    right to left

As you can see, the sizeof is mentioned in the operator man page, because it's not a function but an operator and it works even without parentheses for identifiers like sizeof buf above

OPERATOR(7)               Linux Programmer's Manual              OPERATOR(7)

NAME         top

       operator - C operator precedence and order of evaluation

DESCRIPTION         top

       This manual page lists C operators and their precedence in
       evaluation.

       Operator                            Associativity
       () [] -> .                          left to right
       ! ~ ++ -- + - (type) * & sizeof     right to left
       * / %                               left to right
       + -                                 left to right
       << >>                               left to right
       < <= > >=                           left to right
       == !=                               left to right
       &                                   left to right
       ^                                   left to right
       |                                   left to right
       &&                                  left to right
       ||                                  left to right
       ?:                                  right to left
       = += -= *= /= %= <<= >>= &= ^= |=   right to left
       ,                                   left to right

http://man7.org/linux/man-pages/man7/operator.7.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .