Bug 26533 - error: invalid use of void expression
Summary: error: invalid use of void expression
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-02 20:59 UTC by Kate Minola
Modified: 2006-03-02 21:14 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kate Minola 2006-03-02 20:59:10 UTC
This is probably pretty dodgy C code, but I
find it strange that program foo.c compiles
while program bar.c gives an error.  Is this
a bug?
 
----------- foo.c --------------
#include <stdio.h>
 
int main()
 
{
  int ii;
 
  ii = 276;
  void *vv = (void *)&ii;
}
----------- foo.c --------------

----------- bar.c --------------
#include <stdio.h>
 
int main()
 
{
  int ii;
  void *vv;
 
  ii = 276;
  *vv = (void *)&ii;
}
----------- bar.c --------------
 
% gcc -o foo foo.c
% gcc -o bar bar.c
bar.c: In function ESC)B?main?:
bar.c:10: warning: dereferencing ESC)B?void *? pointer
bar.c:10: error: invalid use of void expression
%
 
For completeness on this report, this was on
 
% gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /usr/local/gcc-4.0.2/src/gcc-4.0.2/configure
--enable-languages=c --prefix=/usr/local/gcc-4.0.2/x86-Linux
Thread model: posix
gcc version 4.0.2
%
Comment 1 Andrew Pinski 2006-03-02 21:14:12 UTC
The first one is ok C even though it is not OK C89 but it is fine C99.
The second one is not ok C at all, since you are deferencing a void pointer.