public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
@ 2013-06-19 7:23 ` mpolacek at gcc dot gnu.org
2013-06-19 7:34 ` vijunag at gmail dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-06-19 7:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
While 4.7 issues warning: value computed is not used, 4.8 and 4.9 do not for
int
main ()
{
char bar = 4;
char *foo = &bar;
(unsigned long *)foo++;
return 0;
}
For 4.7, you can just add cast to void
(void) (unsigned long *)foo++;
to silence the warning.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
2013-06-19 7:23 ` [Bug c/57647] lvalue required as increment operand mpolacek at gcc dot gnu.org
@ 2013-06-19 7:34 ` vijunag at gmail dot com
2013-06-19 7:42 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: vijunag at gmail dot com @ 2013-06-19 7:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #2 from vijay Nag <vijunag at gmail dot com> ---
(In reply to Marek Polacek from comment #1)
> While 4.7 issues warning: value computed is not used, 4.8 and 4.9 do not for
> int
> main ()
> {
> char bar = 4;
> char *foo = &bar;
> (unsigned long *)foo++;
> return 0;
> }
>
> For 4.7, you can just add cast to void
> (void) (unsigned long *)foo++;
> to silence the warning.
Does it work only for int or any type ?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
2013-06-19 7:23 ` [Bug c/57647] lvalue required as increment operand mpolacek at gcc dot gnu.org
2013-06-19 7:34 ` vijunag at gmail dot com
@ 2013-06-19 7:42 ` mpolacek at gcc dot gnu.org
2013-06-19 8:33 ` vijunag at gmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-06-19 7:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It should work for any type, but, why don't you do only foo++;, i.e. drop the
cast? In that case there shouldn't be value computed is not used warning.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2013-06-19 7:42 ` mpolacek at gcc dot gnu.org
@ 2013-06-19 8:33 ` vijunag at gmail dot com
2013-06-19 8:38 ` schwab@linux-m68k.org
` (4 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: vijunag at gmail dot com @ 2013-06-19 8:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #4 from vijay Nag <vijunag at gmail dot com> ---
(In reply to Marek Polacek from comment #3)
> It should work for any type, but, why don't you do only foo++;, i.e. drop
> the cast? In that case there shouldn't be value computed is not used
> warning.
Pointer Arithmetic.
I want to advance the pointer by sizeof(unsigned long) but not by sizeof(char).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2013-06-19 8:33 ` vijunag at gmail dot com
@ 2013-06-19 8:38 ` schwab@linux-m68k.org
2013-06-19 8:40 ` vijunag at gmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2013-06-19 8:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
((unsigned long*)foo)++ and ((unsigned long *)foo++) are not equivalent
expressions. The former is the same as foo = (char *)((unsigned long*)foo +
1), the latter is foo += sizeof(*foo) (and the cast has no effect).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2013-06-19 8:38 ` schwab@linux-m68k.org
@ 2013-06-19 8:40 ` vijunag at gmail dot com
2013-06-19 8:56 ` vijunag at gmail dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 9+ messages in thread
From: vijunag at gmail dot com @ 2013-06-19 8:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #6 from vijay Nag <vijunag at gmail dot com> ---
(In reply to Andreas Schwab from comment #5)
> ((unsigned long*)foo)++ and ((unsigned long *)foo++) are not equivalent
> expressions. The former is the same as foo = (char *)((unsigned long*)foo +
> 1), the latter is foo += sizeof(*foo) (and the cast has no effect).
((unsigned long*)foo)++ is no longer a valid C expression for the cast
evaluates it to be an R-value rather than L-value
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2013-06-19 8:40 ` vijunag at gmail dot com
@ 2013-06-19 8:56 ` vijunag at gmail dot com
2013-06-19 9:04 ` schwab@linux-m68k.org
2015-02-26 19:01 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 9+ messages in thread
From: vijunag at gmail dot com @ 2013-06-19 8:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #7 from vijay Nag <vijunag at gmail dot com> ---
(In reply to vijay Nag from comment #6)
> (In reply to Andreas Schwab from comment #5)
> > ((unsigned long*)foo)++ and ((unsigned long *)foo++) are not equivalent
> > expressions. The former is the same as foo = (char *)((unsigned long*)foo +
> > 1), the latter is foo += sizeof(*foo) (and the cast has no effect).
>
((unsigned long*)foo)++ is no longer a valid C expression for the cast
evaluates it to be an R-value rather than L-value. Why is the second
expression
evaluating as foo += sizeof(*foo) ? ()(parentheses) comes before ++(postfix)
although they both have the same precedence but associativity is from left to
right.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2013-06-19 8:56 ` vijunag at gmail dot com
@ 2013-06-19 9:04 ` schwab@linux-m68k.org
2015-02-26 19:01 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2013-06-19 9:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
--- Comment #8 from Andreas Schwab <schwab@linux-m68k.org> ---
Postfix operators bind stronger than cast operators. If you need help on the C
language then bugzilla is not the right place.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/57647] lvalue required as increment operand
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2013-06-19 9:04 ` schwab@linux-m68k.org
@ 2015-02-26 19:01 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-02-26 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Seems there's nothing to do here.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-02-26 18:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-57647-4@http.gcc.gnu.org/bugzilla/>
2013-06-19 7:23 ` [Bug c/57647] lvalue required as increment operand mpolacek at gcc dot gnu.org
2013-06-19 7:34 ` vijunag at gmail dot com
2013-06-19 7:42 ` mpolacek at gcc dot gnu.org
2013-06-19 8:33 ` vijunag at gmail dot com
2013-06-19 8:38 ` schwab@linux-m68k.org
2013-06-19 8:40 ` vijunag at gmail dot com
2013-06-19 8:56 ` vijunag at gmail dot com
2013-06-19 9:04 ` schwab@linux-m68k.org
2015-02-26 19:01 ` mpolacek at gcc dot gnu.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).