Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7759419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:37:27+00:00 2026-06-01T13:37:27+00:00

Why does gcc allow extern declarations of type void? Is this an extension or

  • 0

Why does gcc allow extern declarations of type void? Is this an extension or
standard C? Are there acceptable uses for this?

I am guessing it is an extension, but I don’t find it mentioned at:
http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/C-Extensions.html

$ cat extern_void.c
extern void foo; /* ok in gcc 4.3, not ok in Visual Studio 2008 */
void* get_foo_ptr(void) { return &foo; }

$ gcc -c extern_void.c # no compile error

$ gcc --version | head -n 1
gcc (Debian 4.3.2-1.1) 4.3.2

Defining foo as type void is of course a compile error:

$ gcc -c -Dextern= extern_void.c
extern_void.c:1: error: storage size of ‘foo’ isn’t known

For comparison, Visual Studio 2008 gives an error on the extern declaration:

$ cl /c extern_void.c 
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

extern_void.c
extern_void.c(1) : error C2182: 'foo' : illegal use of type 'void'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:37:28+00:00Added an answer on June 1, 2026 at 1:37 pm

    Strangely enough (or perhaps not so strangely…) it looks to me like gcc is correct to accept this.

    If this was declared static instead of extern, then it would have internal linkage, and §6.9.2/3 would apply:

    If the declaration of an identifier for an object is a tentative definition and has internal
    linkage, the declared type shall not be an incomplete type.

    If it didn’t specify any storage class (extern, in this case), then §6.7/7 would apply:

    If an identifier for an object is declared with no linkage, the type for the object shall be complete by the end of its declarator, or by the end of its init-declarator if it has an
    initializer; in the case of function arguments (including in prototypes), it is the adjusted type (see 6.7.5.3) that is required to be complete.

    I either of these cases, void would not work, because (§6.2.5/19):

    The void type […] is an incomplete type that cannot be completed.

    None of those applies, however. That seems to leave only the requirements of §6.7.2/2, which seems to allow a declaration of a name with type void:

    At least one type specifier shall be given in the declaration specifiers in each declaration,
    and in the specifier-qualifier list in each struct declaration and type name. Each list of
    type specifiers shall be one of the following sets (delimited by commas, when there is
    more than one set on a line); the type specifiers may occur in any order, possibly
    intermixed with the other declaration specifiers.

    • void
    • char
    • signed char

    [ … more types elided]

    I’m not sure that’s really intentional — I suspect the void is really intended for things like derived types (e.g., pointer to void) or the return type from a function, but I can’t find anything that directly specifies that restriction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know MSVC can do this via a pragma message -> http://support.microsoft.com/kb/155196 Does gcc
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
Does gcc have memory alignment pragma, akin #pragma vector aligned in Intel compiler? I
On a Unix system, where does gcc look for header files? I spent a
I want to preprocess files before gcc actually does its own preprocessing and parsing.
Consider the code below. I don't understand why my GCC compiler does not try
Does anyone know how I can for the g++ or gcc runtime to scramble
Does anyone have experience with LLVM , llvm-gcc , or Clang ? The whole
main() { printf(Hello World.); } Why does no warning is produced in gcc compiler
The GCC manual says: -fobjc-direct-dispatch Allow fast jumps to the message dispatcher. On Darwin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.