Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5381
| From | "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Is this valid code or UB? |
| Date | 2011-05-24 02:38 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <ireub4$q65$1@dont-email.me> (permalink) |
| References | <UKACp.14009$UY3.5807@newsfe20.ams2> <aa7019f5-96fc-4cd1-a63a-ccb5a3687e72@z7g2000prh.googlegroups.com> |
* Joshua Maurice, on 24.05.2011 01:35:
> On May 23, 2:57 pm, "Paul"<pchris...@yahoo.co.uk> wrote:
>> Yes I'm still arguing about arrays. Anyway consider the following:
>>
>> int main(){
>> int (*p)[3]=0;
>> std::cout<<*p<<std::endl;
>> std::cout<< typeid(*p).name()<<std::endl;
>> std::cout<< sizeof(*p);
>>
>> }
>>
>> Does a valid array type object exist?
>> Is it UB because it dereferences a null pointer?
>
> Add a missing #include<iostream> for starters.
>
[snip long descent into standard]
He he.
There is a non-normative *comment* somewhere at the start of the standard that
states pretty off-hand that dereferencing a null pointer is UB. Then there is
normative text regarding typeid that says that it's OK for the typeid argument.
Which makes sense, since the compiler can add checking there.
This is a well-known "almost-defect". I think but I am not sure that it has been
fixed in C++0x.
Cheers & hth.,
- Alf
--
blog at <url: http://alfps.wordpress.com>
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this valid code or UB? "Paul" <pchristor@yahoo.co.uk> - 2011-05-23 22:57 +0100
Re: Is this valid code or UB? Leigh Johnston <leigh@i42.co.uk> - 2011-05-23 23:05 +0100
Re: Is this valid code or UB? Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2011-05-23 16:04 -0700
Re: Is this valid code or UB? Ian Collins <ian-news@hotmail.com> - 2011-05-24 11:15 +1200
Re: Is this valid code or UB? Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-23 16:35 -0700
Re: Is this valid code or UB? "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-24 02:38 +0200
Re: Is this valid code or UB? Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-23 18:36 -0700
csiph-web