0

It is known that:

  • implicit declaration of function is invalid
  • implicit declaration of variable is invalid

Which implicit declarations are allowed / valid?

One example is identifier __func__. Are there other examples?

cigien
  • 57,834
  • 11
  • 73
  • 112
pmor
  • 5,392
  • 4
  • 17
  • 36
  • 2
    What is the implicit declaration? – tstanisl Sep 28 '21 at 20:54
  • Maybe `main` function? – tstanisl Sep 28 '21 at 21:06
  • 1
    `__func__` is the one and only context where the current standard mentions "implicit declaration" or "implicitly declared". There are no other implicitly declared things. – n. m. could be an AI Sep 28 '21 at 21:09
  • So you found this text about `__func__` in 6.4.2.2 predefined identifiers. What other predefined identifiers do you find in that chapter other than `__func__`? And that would be the answer to the question. – Lundin Sep 29 '21 at 08:59
  • @n.1.8e9-where's-my-sharem. Can you provide an answer "There are no other implicitly declared things"? – pmor Sep 29 '21 at 11:44
  • @Lundin Out of curiosity: why both gcc and clang define `__func__` at file scope? msvc doesn't. – pmor Sep 29 '21 at 15:28
  • Does it? Hmm well that sounds curious. And it sounds like a potentially good new question if you can post your research regarding how you came to that conclusion. – Lundin Sep 29 '21 at 15:35
  • @Lundin Both gcc and clang allow at file scope to assign `__func__` and apply `sizeof` to it while issuing a warning following by generation of an executable. While msvc issues an error. Live demo: https://godbolt.org/z/Gnh47efc7. – pmor Sep 29 '21 at 16:43
  • I guess the standard doesn't really mention what happens if used at file scope. Printing the pointer from your example just gives an empty string on gcc and clang. "...immediately following the opening brace of each function definition" kind of implies that `__func__` has no business outside a function definition though. Maybe you have found the first example in history where MSVC actually has better conformance than other compilers :) – Lundin Sep 30 '21 at 06:34

0 Answers0