Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13246 > unrolled thread
| Started by | Novice Coder <extngg1@gmail.com> |
|---|---|
| First post | 2012-01-11 09:08 -0800 |
| Last post | 2012-01-14 01:52 -0800 |
| Articles | 4 on this page of 44 — 15 participants |
Back to article view | Back to comp.lang.c++
Simultaneous read and write on a variable in C++ Novice Coder <extngg1@gmail.com> - 2012-01-11 09:08 -0800
Re: Simultaneous read and write on a variable in C++ Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-11 12:28 -0500
Re: Simultaneous read and write on a variable in C++ Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-12 13:07 -0500
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 10:11 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 18:46 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 11:18 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 19:28 +0000
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 19:41 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 11:46 -0800
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 11:44 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 19:46 +0000
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 19:53 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 12:01 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 20:10 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 12:13 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 20:31 +0000
Re: Simultaneous read and write on a variable in C++ scott@slp53.sl.home (Scott Lurndal) - 2012-01-13 18:12 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 11:37 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 19:56 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 11:58 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 20:04 +0000
Re: Simultaneous read and write on a variable in C++ Juha Nieminen <nospam@thanks.invalid> - 2012-01-13 06:34 +0000
Re: Simultaneous read and write on a variable in C++ SG <s.gesemann@gmail.com> - 2012-01-11 13:11 -0800
Re: Simultaneous read and write on a variable in C++ Calum <spambox@calumgrant.net> - 2012-01-11 13:18 -0800
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 03:11 -0800
Re: Simultaneous read and write on a variable in C++ "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-01-12 16:35 +0100
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 08:06 -0800
Re: Simultaneous read and write on a variable in C++ gwowen <gwowen@gmail.com> - 2012-01-12 07:48 -0800
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-12 07:55 -0800
Re: Simultaneous read and write on a variable in C++ Gareth Owen <gwowen@gmail.com> - 2012-01-12 19:36 +0000
Re: Simultaneous read and write on a variable in C++ Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-12 16:31 -0500
Re: Simultaneous read and write on a variable in C++ Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-13 02:05 -0800
Re: Simultaneous read and write on a variable in C++ Goran <goran.pusic@gmail.com> - 2012-01-13 04:24 -0800
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoonsaurav.nit@gmail.com> - 2012-01-13 04:52 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 12:39 +0000
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 12:50 +0000
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 12:58 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoon@parallocity.com> - 2012-01-12 05:55 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 13:59 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoon@parallocity.com> - 2012-01-12 06:14 -0800
Re: Simultaneous read and write on a variable in C++ Leigh Johnston <leigh@i42.co.uk> - 2012-01-12 14:30 +0000
Re: Simultaneous read and write on a variable in C++ Juha Nieminen <nospam@thanks.invalid> - 2012-01-12 14:34 +0000
Re: Simultaneous read and write on a variable in C++ Prasoon Saurav <prasoon@parallocity.com> - 2012-01-12 05:54 -0800
Re: Simultaneous read and write on a variable in C++ BCFD36 <bcfd36@cruzio.com> - 2012-01-14 01:52 -0800
Page 3 of 3 — ← Prev page 1 2 [3]
| From | Leigh Johnston <leigh@i42.co.uk> |
|---|---|
| Date | 2012-01-12 14:30 +0000 |
| Message-ID | <ke6dnfYVWaAHc5PSnZ2dnUVZ8jCdnZ2d@giganews.com> |
| In reply to | #13281 |
On 12/01/2012 14:14, Prasoon Saurav wrote:
> On Jan 12, 6:59 pm, Leigh Johnston<le...@i42.co.uk> wrote:
>> On 12/01/2012 13:55, Prasoon Saurav wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Jan 12, 5:58 pm, Leigh Johnston<le...@i42.co.uk> wrote:
>>>> On 12/01/2012 12:50, Leigh Johnston wrote:
>>
>>>>> On 11/01/2012 17:08, Novice Coder wrote:
>>>>>> Here is the code
>>
>>>>>> int main()
>>>>>> {
>>>>>> char *p;
>>>>>> char a[]={"Hello"};
>>>>>> (p=a)[0]; // This line
>>>>>> return 0;
>>>>>> }
>>
>>>>>> Is the behaviour of this code undefined in C++?
>>
>>>>> I vote that it is not UB.
>>
>>>>> (p=a)[0] is equivalent to *(p=a); if *(p=a) is UB then surely *(p2++) is
>>>>> also UB? Clearly nonsense. (p=a)[0] + (p=a+1)[0] is UB however.
>>
>>>> I meant '*(++p2)' not '*(p2++)'.
>>
>>>> /Leigh
>>
>>> Yes I believe *(++p2) is UB too.
>>
>> Bullshit; are you trolling?
>>
>> /Leigh
>
> Huh?
The following piece of code is not UB:
int main()
{
const char a[] = "Hello, world!";
const char* p = a;
do
{
std::cout << *p;
} while(*++p);
}
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2012-01-12 14:34 +0000 |
| Message-ID | <4f0eef72$0$4367$7b1e8fa0@news.nbl.fi> |
| In reply to | #13281 |
Prasoon Saurav <prasoon@parallocity.com> wrote: > On Jan 12, 6:59 pm, Leigh Johnston <le...@i42.co.uk> wrote: >> Bullshit; are you trolling? >> >> /Leigh > > Huh? Don't worry. He's one of those people who seem to think that "trolling" means "disagrees with me" (and mostly uses it as an insult).
[toc] | [prev] | [next] | [standalone]
| From | Prasoon Saurav <prasoon@parallocity.com> |
|---|---|
| Date | 2012-01-12 05:54 -0800 |
| Message-ID | <8b6281f5-a320-4520-b9da-d7d6773be588@iu7g2000pbc.googlegroups.com> |
| In reply to | #13270 |
On Jan 12, 5:50 pm, Leigh Johnston <le...@i42.co.uk> wrote:
> On 11/01/2012 17:08, Novice Coder wrote:
>
> > Here is the code
>
> > int main()
> > {
> > char *p;
> > char a[]={"Hello"};
> > (p=a)[0]; // This line
> > return 0;
> > }
>
> > Is the behaviour of this code undefined in C++?
>
> I vote that it is not UB.
>
> (p=a)[0] is equivalent to *(p=a); if *(p=a) is UB then surely *(p2++) is
> also UB? Clearly nonsense. (p=a)[0] + (p=a+1)[0] is UB however.
>
> /Leigh
*(p2++) isn't UB. p++ evaluates to 'p'(a copy) because the result of
post increment is the "value"(old) of the operand. In (p=a) the access/
dereference is on p (lvalue) itself and not on a copy of 'p'.
Assignment operation is defined in section 5.17
"The result of the assignment operation is the value stored in the
left operand after the assignment has taken place; the result
is an lvalue."
This is very confusing. :P
HTH
Prasoon
[toc] | [prev] | [next] | [standalone]
| From | BCFD36 <bcfd36@cruzio.com> |
|---|---|
| Date | 2012-01-14 01:52 -0800 |
| Message-ID | <jerj8d$utn$1@speranza.aioe.org> |
| In reply to | #13246 |
On 1/11/12 9:08 AM, Novice Coder wrote:
> Here is the code
>
> int main()
> {
> char *p;
> char a[]={"Hello"};
> (p=a)[0]; // This line
> return 0;
> }
>
> Is the behaviour of this code undefined in C++?
I read the whole thread. I'll never get those minutes back. Whether or
not it is well defined is not relevant except maybe in an academic
sense. The code is crap. Posit that it is well defined. So what. It is
obscure. It is opaque. There are other ways to make it clearer what you
want to do. This looks like something designed to try to break the compiler.
Just because something is legal, well defined, and you saw it somewhere
doesn't make it a good idea.
--
Dave Scruggs
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | comp.lang.c++
csiph-web