Greetings,
Will the following definition invoke
undefined behaviour, either at file scope
or block scope?
char s[500000];
--
"We approached the case, you remember Watson," said
Mr. Homles, "with an absolutely blank mind, which is
always an advantage."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Vijay Kumar R Zanvar" <vijoeyz@globaledgesoft.com> writes:
> Will the following definition invoke
> undefined behaviour, either at file scope
> or block scope?
>
> char s[500000];
Yes. An implementation need not support objects larger than
65535 bytes.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Dickopp <expires-2004-05-31@zero-based.org> wrote:
> "Vijay Kumar R Zanvar" <vijoeyz@globaledgesoft.com> writes:
>
> > Will the following definition invoke
> > undefined behaviour, either at file scope
> > or block scope?
> >
> > char s[500000];
>
> Yes. An implementation need not support objects larger than
> 65535 bytes.
AFAICT it still doesn't invoke UB. Any implementation may reject it as
being too large, but if it accepts this definition, it must accept it as
a normal array.
Richard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In <408e3762.2430372449@news.individual.net> rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
>Martin Dickopp <expires-2004-05-31@zero-based.org> wrote:
>
>> "Vijay Kumar R Zanvar" <vijoeyz@globaledgesoft.com> writes:
>>
>> > Will the following definition invoke
>> > undefined behaviour, either at file scope
>> > or block scope?
>> >
>> > char s[500000];
>>
>> Yes. An implementation need not support objects larger than
>> 65535 bytes.
That's true for hosted C99 implementations *only*. Hosted C89
implementations need not support more than one object of 32767 bytes.
>AFAICT it still doesn't invoke UB. Any implementation may reject it as
>being too large, but if it accepts this definition, it must accept it as
>a normal array.
I'm afraid Martin is right here, as I can't find the chapter and verse
which requires the implementation to emit a diagnostic if the size is
too large.
So, a maximally portable program needing a 500000 byte array will have
to check first that (size_t)-1 > 500000 and then try to allocate it
dynamically.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dan.Pop@cern.ch (Dan Pop) wrote in message news:<c6li5e$mo1$2@sunnews.cern.ch>...
> I'm afraid Martin is right here, as I can't find the chapter and verse
> which requires the implementation to emit a diagnostic if the size is
> too large.
(C89) 5.1.1.3 Diagnostics: A conforming implementation shall produce
at least one diagnostic message (...) for every translation unit that
contains a violation of any syntax rule or constraint.
I would read "constraint" to include the translation limits.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On 27 Apr 2004 16:09:15 -0700, robertwessel2@yahoo.com (Robert Wessel)
wrote in comp.lang.c:
> Dan.Pop@cern.ch (Dan Pop) wrote in message news:<c6li5e$mo1$2@sunnews.cern.ch>...
> > I'm afraid Martin is right here, as I can't find the chapter and verse
> > which requires the implementation to emit a diagnostic if the size is
> > too large.
>
>
> (C89) 5.1.1.3 Diagnostics: A conforming implementation shall produce
> at least one diagnostic message (...) for every translation unit that
> contains a violation of any syntax rule or constraint.
>
> I would read "constraint" to include the translation limits.
Your interpretation is incorrect. The term "constraint" itself is
specifically defined in the standard:
"restriction, either syntactic or semantic, by which the exposition of
language elements is to be interpreted".
Even more specifically, constraint violations are enumerated in the
standard by appearing in specifically labeled clauses. A program that
fails due to exceeding translation limits does not exhibit a
constraint violation, and no diagnostic is required.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~