public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1
@ 2005-06-15 23:46 jboone at logitel dot com
  2005-06-15 23:47 ` [Bug preprocessor/22086] " jboone at logitel dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: jboone at logitel dot com @ 2005-06-15 23:46 UTC (permalink / raw)
  To: gcc-bugs

To my surprise, I was able to compile the following code snippet:

        void * pv = NULL;
        printf("sizeof: %d\n", sizeof(*pv));

I believe there are two problems here. First, I should not be able to
dereference a void pointer, as I do inside sizeof(). Secondly, even if I could,
should it return 1, not 0? I do not have access to the C specification, but
would be mortified (and apologetic) if this were correct behavior.

Attached is a sample program, and the .i output of my gcc compiler.

gcc -v -save-temps -Wall -o void-sizeof void-sizeof.c

---------
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/cc1 -E -quiet -v -D__GNUC__=3
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 void-sizeof.c -Wall void-sizeof.i
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/cc1 -fpreprocessed void-sizeof.i
-quiet -dumpbase void-sizeof.c -auxbase void-sizeof -Wall -version -o void-sizeof.s
GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (i386-redhat-linux)
        compiled by GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7).
GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15750
 as -V -Qy -o void-sizeof.o void-sizeof.s
GNU assembler version 2.15.90.0.3 (i386-redhat-linux) using BFD version
2.15.90.0.3 20040415
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o void-sizeof
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crt1.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crti.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtbegin.o
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../.. void-sizeof.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtend.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crtn.o
---------

-- 
           Summary: void * dereferenced in sizeof() yields 1
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jboone at logitel dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/22086] void * dereferenced in sizeof() yields 1
  2005-06-15 23:46 [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1 jboone at logitel dot com
@ 2005-06-15 23:47 ` jboone at logitel dot com
  2005-06-15 23:48 ` jboone at logitel dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: jboone at logitel dot com @ 2005-06-15 23:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jboone at logitel dot com  2005-06-15 23:47 -------
Created an attachment (id=9096)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9096&action=view)
C sample


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug preprocessor/22086] void * dereferenced in sizeof() yields 1
  2005-06-15 23:46 [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1 jboone at logitel dot com
  2005-06-15 23:47 ` [Bug preprocessor/22086] " jboone at logitel dot com
@ 2005-06-15 23:48 ` jboone at logitel dot com
  2005-06-15 23:50 ` [Bug c/22086] " pinskia at gcc dot gnu dot org
  2005-06-16  0:03 ` jboone at logitel dot com
  3 siblings, 0 replies; 6+ messages in thread
From: jboone at logitel dot com @ 2005-06-15 23:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jboone at logitel dot com  2005-06-15 23:48 -------
Created an attachment (id=9097)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9097&action=view)
Intermediate output from gcc


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/22086] void * dereferenced in sizeof() yields 1
  2005-06-15 23:46 [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1 jboone at logitel dot com
  2005-06-15 23:47 ` [Bug preprocessor/22086] " jboone at logitel dot com
  2005-06-15 23:48 ` jboone at logitel dot com
@ 2005-06-15 23:50 ` pinskia at gcc dot gnu dot org
  2005-06-16  0:03 ` jboone at logitel dot com
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-15 23:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-15 23:50 -------
This is a GCC extension. sizeof(void) is invalid C and should error out and does with -pedantic-errors

The reason why it is 1 and not 0 is because it is also a GNU extension that you can increment a void 
pointer like a char pointer.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|preprocessor                |c
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/22086] void * dereferenced in sizeof() yields 1
  2005-06-15 23:46 [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1 jboone at logitel dot com
                   ` (2 preceding siblings ...)
  2005-06-15 23:50 ` [Bug c/22086] " pinskia at gcc dot gnu dot org
@ 2005-06-16  0:03 ` jboone at logitel dot com
  3 siblings, 0 replies; 6+ messages in thread
From: jboone at logitel dot com @ 2005-06-16  0:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jboone at logitel dot com  2005-06-16 00:03 -------
Subject: Re:  void * dereferenced in sizeof() yields 1

My apologies. And thanks for the polite explanation. I'll wade through 
the man pages and start using a more appropriate set of compile options. 
Thanks,

    - Jared

pinskia at gcc dot gnu dot org wrote:

>------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-15 23:50 -------
>This is a GCC extension. sizeof(void) is invalid C and should error out and does with -pedantic-errors
>
>The reason why it is 1 and not 0 is because it is also a GNU extension that you can increment a void 
>pointer like a char pointer.
>
>  
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/22086] void * dereferenced in sizeof() yields 1
       [not found] <bug-22086-10834@http.gcc.gnu.org/bugzilla/>
@ 2008-12-18  1:35 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-18  1:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2008-12-18 01:33 -------
*** Bug 38563 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |derek at knosof dot co dot
                   |                            |uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22086


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-12-18  1:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-15 23:46 [Bug preprocessor/22086] New: void * dereferenced in sizeof() yields 1 jboone at logitel dot com
2005-06-15 23:47 ` [Bug preprocessor/22086] " jboone at logitel dot com
2005-06-15 23:48 ` jboone at logitel dot com
2005-06-15 23:50 ` [Bug c/22086] " pinskia at gcc dot gnu dot org
2005-06-16  0:03 ` jboone at logitel dot com
     [not found] <bug-22086-10834@http.gcc.gnu.org/bugzilla/>
2008-12-18  1:35 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).