10

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 Mar 21 '17 at 14:05
9

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? – user1527227 May 14 '14 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 May 14 '14 at 20:57
  • Thanks. Last question: Is there an official documentation for operators like this? – user1527227 May 14 '14 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 May 14 '14 at 21:03
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.