KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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'
Tags (comma-separated)
Save Edits
Cancel