This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: const void* and goto *expr
- From: Eus <eus at member dot fsf dot org>
- To: Igor Bukanov <igor at mir2 dot org>
- Cc: GCC Help Mailing List <gcc-help at gcc dot gnu dot org>
- Date: Fri, 27 Jun 2008 00:08:14 -0700 (PDT)
- Subject: Re: const void* and goto *expr
- Reply-to: eus at member dot fsf dot org
Hi Ho!
--- On Wed, 6/25/08, "Igor Bukanov" <igor@mir2.org> wrote:
> But this is what GCC does already as the example demonstrates: it
> accepts const void* as the type of exp in "goto *exp" in addition to
> plain void*. This is both with gcc and g++. The question is this
> intended behavior? If the answer is yes, then the documentation has a
> bug. If the answer is no, then this is a bug in GCC.
Yes, it is intended. But, neither the doc nor GCC has a bug.
Why? Because the goto operator can be considered as the following function:
void goto(const void *ptr);
Since `const void *ptr' is a superset of `void *ptr' as Dan mentioned, goto can accept `void *ptr' too.
As another illustration, a function like:
int strcmp(const char *a, const char *b);
should accept non-constant pointers to character as its arguments, shouldn't it?
> The issue came up when compiling with the Intel compiler a code with
> computed code that used const void*. GCC was dealing with that code
> just fine but icc insisted that the type should be void*. I guess
> Intel folks just followed documentation when implemented the
> computed-goto in their compiler.
I guess Intel folks walked the wrong path of not knowing that `const void *' is the superset of `void *'.
> Regards, Igor
Best regards,
Eus