public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31712]  New: no warning on implicit cast from int to pointer
@ 2007-04-26 11:11 christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 11:12 ` [Bug c/31712] " christoph dot wintersteiger at inf dot ethz dot ch
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: christoph dot wintersteiger at inf dot ethz dot ch @ 2007-04-26 11:11 UTC (permalink / raw)
  To: gcc-bugs

Mixing up variables when working with strings does not trigger a warning.

Example:

int main(void)
{
int plen;
char *ptr;

plen[ptr]='\0'; /* (char*)'th element of an int */

return 0;
}

in line 6, plen[ptr]='\0';, plen is implicitly casted to a pointer and ptr is
implicitly casted to an unsigned. At least when casting the int to a pointer,
there should be a warning. 

This behavior can be reproduced in, at least, versions 2.95, 3.2.3 and 4.1.2 of
gcc. Adding -Wall -g -ansi -pedantic -std=c99 does not help.


-- 
           Summary: no warning on implicit cast from int to pointer
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: christoph dot wintersteiger at inf dot ethz dot ch
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug c/31712] no warning on implicit cast from int to pointer
  2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
@ 2007-04-26 11:12 ` christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 11:18 ` schwab at suse dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: christoph dot wintersteiger at inf dot ethz dot ch @ 2007-04-26 11:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from christoph dot wintersteiger at inf dot ethz dot ch  2007-04-26 12:12 -------
Created an attachment (id=13448)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13448&action=view)
Testcase, should produce a warning but doesn't.


-- 


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


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

* [Bug c/31712] no warning on implicit cast from int to pointer
  2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 11:12 ` [Bug c/31712] " christoph dot wintersteiger at inf dot ethz dot ch
@ 2007-04-26 11:18 ` schwab at suse dot de
  2007-04-26 11:32 ` christoph dot wintersteiger at inf dot ethz dot ch
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab at suse dot de @ 2007-04-26 11:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from schwab at suse dot de  2007-04-26 12:18 -------
There is no implicit cast here.  a[b] is the same as (*((a)+(b))), and since
addition is commutative, this is the same as (b)[a].


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c/31712] no warning on implicit cast from int to pointer
  2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 11:12 ` [Bug c/31712] " christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 11:18 ` schwab at suse dot de
@ 2007-04-26 11:32 ` christoph dot wintersteiger at inf dot ethz dot ch
  2007-04-26 14:56 ` pinskia at gcc dot gnu dot org
  2007-04-26 15:04 ` christoph dot wintersteiger at inf dot ethz dot ch
  4 siblings, 0 replies; 6+ messages in thread
From: christoph dot wintersteiger at inf dot ethz dot ch @ 2007-04-26 11:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from christoph dot wintersteiger at inf dot ethz dot ch  2007-04-26 12:31 -------
(In reply to comment #2)
> There is no implicit cast here.  a[b] is the same as (*((a)+(b))), and since
> addition is commutative, this is the same as (b)[a].
> 

Thanks for clarifying. I still think it's completely confusing to have
a[b]==b[a] in general, but that's probably something that can't be changed
easily.


-- 


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


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

* [Bug c/31712] no warning on implicit cast from int to pointer
  2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
                   ` (2 preceding siblings ...)
  2007-04-26 11:32 ` christoph dot wintersteiger at inf dot ethz dot ch
@ 2007-04-26 14:56 ` pinskia at gcc dot gnu dot org
  2007-04-26 15:04 ` christoph dot wintersteiger at inf dot ethz dot ch
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-26 14:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-04-26 15:56 -------
>Thanks for clarifying. I still think it's completely confusing to have
> a[b]==b[a] in general, but that's probably something that can't be changed
> easily.

Well, this is what the C standard says how this is defined.  C++ on the other
hand, is different.


-- 


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


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

* [Bug c/31712] no warning on implicit cast from int to pointer
  2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
                   ` (3 preceding siblings ...)
  2007-04-26 14:56 ` pinskia at gcc dot gnu dot org
@ 2007-04-26 15:04 ` christoph dot wintersteiger at inf dot ethz dot ch
  4 siblings, 0 replies; 6+ messages in thread
From: christoph dot wintersteiger at inf dot ethz dot ch @ 2007-04-26 15:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from christoph dot wintersteiger at inf dot ethz dot ch  2007-04-26 16:03 -------
Subject: Re:  no warning on implicit cast from int to pointer

On Thu, 2007-04-26 at 14:56 +0000, pinskia at gcc dot gnu dot org wrote:
> 
> ------- Comment #4 from pinskia at gcc dot gnu dot org  2007-04-26 15:56 -------
> >Thanks for clarifying. I still think it's completely confusing to have
> > a[b]==b[a] in general, but that's probably something that can't be changed
> > easily.
> 
> Well, this is what the C standard says how this is defined.  C++ on the other
> hand, is different.
> 
> 

Yep, you're right, the standard says that. The C++ standard says the
same for standard-[] (c-type arrays, I guess not for custom operator[]s
in classes). 

Christoph


-- 


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


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

end of thread, other threads:[~2007-04-26 15:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-26 11:11 [Bug c/31712] New: no warning on implicit cast from int to pointer christoph dot wintersteiger at inf dot ethz dot ch
2007-04-26 11:12 ` [Bug c/31712] " christoph dot wintersteiger at inf dot ethz dot ch
2007-04-26 11:18 ` schwab at suse dot de
2007-04-26 11:32 ` christoph dot wintersteiger at inf dot ethz dot ch
2007-04-26 14:56 ` pinskia at gcc dot gnu dot org
2007-04-26 15:04 ` christoph dot wintersteiger at inf dot ethz dot ch

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).