char s[500000];

  • Thread starter Vijay Kumar R Zanvar
  • Start date
V

Vijay Kumar R Zanvar

Greetings,
Will the following definition invoke
undefined behaviour, either at file scope
or block scope?

char s[500000];
 
M

Martin Dickopp

Vijay Kumar R Zanvar said:
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
 
R

Richard Bos

Martin Dickopp said:
Vijay Kumar R Zanvar said:
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
 
D

Dan Pop

In said:
Martin Dickopp said:
Vijay Kumar R Zanvar said:
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
 
Z

ZAPPLE

Martin Dickopp said:
Vijay Kumar R Zanvar said:
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

Hi Guys,
What is all about? Is this just a testing question or what? Instead if
you tell us what is the problem all about? we can have a great
discussion.
What do you think about this?
ZAPPLE - My computer is a Clever machine
 
R

Robert Wessel

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

Jack Klein

(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.
 
M

Mark McIntyre

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

This is true, but bear in mind that
"VAXC-I-SUCCESS Succesful compilation"
is a diagnostic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top