473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

char s[500000];

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."
Nov 14 '05 #1
7 1301
"Vijay Kumar R Zanvar" <vi*****@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. \_/
Nov 14 '05 #2
Martin Dickopp <ex****************@zero-based.org> wrote:
"Vijay Kumar R Zanvar" <vi*****@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
Nov 14 '05 #3
In <40*****************@news.individual.net> rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Martin Dickopp <ex****************@zero-based.org> wrote:
"Vijay Kumar R Zanvar" <vi*****@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: Da*****@ifh.de
Nov 14 '05 #4
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40*****************@news.individual.net>...
Martin Dickopp <ex****************@zero-based.org> wrote:
"Vijay Kumar R Zanvar" <vi*****@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


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
Nov 14 '05 #5
Da*****@cern.ch (Dan Pop) wrote in message news:<c6**********@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.
Nov 14 '05 #6
On 27 Apr 2004 16:09:15 -0700, ro***********@yahoo.com (Robert Wessel)
wrote in comp.lang.c:
Da*****@cern.ch (Dan Pop) wrote in message news:<c6**********@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/~a...FAQ-acllc.html
Nov 14 '05 #7
On 27 Apr 2004 16:09:15 -0700, in comp.lang.c , ro***********@yahoo.com
(Robert Wessel) wrote:
Da*****@cern.ch (Dan Pop) wrote in message news:<c6**********@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.


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

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christopher Benson-Manica | last post by:
I need a smart char * class, that acts like a char * in all cases, but lets you do some std::string-type stuff with it. (Please don't say to use std::string - it's not an option...). This is my...
5
by: Alex Vinokur | last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c > ben19777@hotmail.com (Ben) wrote: > > 2) Structure casted into an...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
4
by: ravinderthakur | last post by:
hi all experts, can anybody explain me the difference between the unsigned char and char in c/c++ langugage. specifically how does this affects the c library fucntion such as strcat,strtok...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
4
by: Paul Brettschneider | last post by:
Hello all, consider the following code: typedef char T; class test { T *data; public: void f(T, T, T); void f2(T, T, T);
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.