473,398 Members | 2,343 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,398 software developers and data experts.

size limits for string literals

Do the standards say anything about size limits for string literals (min
size, max size)? I want to know this to make sure that my code is portable.
The program in question is ANSI C89, but I would also be interested in
whether or not ISO C99 changed the limits (if any exist).


Mar 25 '08 #1
7 7716
"copx" <co**@gazeta.plwrote:
Do the standards say anything about size limits for string literals (min
size, max size)? I want to know this to make sure that my code is portable.
The program in question is ANSI C89, but I would also be interested in
whether or not ISO C99 changed the limits (if any exist).
Minima, of course not; an empty string is valid in any language. The
notional limit on the size of a string literal in The One Program (and
see discussions of that program in this newsgroup over the years to know
why all these limits are always slightly misleading) is 509 characters
in C89, and 4095 in C99. Both of these are valid for normal and wide
strings, and _after_ concatenation (so you can't get around them with a
trick like "almost_too_long_string" "another_long_string").

Richard
Mar 25 '08 #2
copx said:
Do the standards say anything about size limits for string literals (min
size, max size)?
Clearly, the minimum size is 1 (because sizeof "" is 1).

The maximum size of a string literal or wide string literal (after
concatenation, e.g. from "foo" "bar" to "foobar") that an implementation
*must* support is 509 in C90. This has been increased to 4095 in C99.

So if all your string literals are shorter than that, you will not break
anything. If you make them longer, you're relying on your implementation
being nice to you.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 25 '08 #3
In article <47****************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
>Minima, of course not; an empty string is valid in any language.
I believe I've worked with some languages which did not support
empty strings, but it has been long enough since then that I could
not name any specifics.
--
"What we have to do is to be forever curiously testing new
opinions and courting new impressions." -- Walter Pater
Mar 25 '08 #4
copx wrote:
>
Do the standards say anything about size limits for string literals (min
size, max size)? I want to know this to make sure that my code is portable.
The program in question is ANSI C89, but I would also be interested in
whether or not ISO C99 changed the limits (if any exist).
Yes they do. I believe the C89/C90/C95 limit is roughly 510 bytes,
and that C99 expanded it to roughly 1020 bytes. Look in the C
standard.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/ (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2(C99, txt)
<http://www.dinkumware.com/c99.aspx (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 26 '08 #5

"copx" <co**@gazeta.plschrieb im Newsbeitrag
news:fs**********@inews.gazeta.pl...
Do the standards say anything about size limits for string literals (min
size, max size)?
[snip]

Thanks everyone!
Mar 26 '08 #6
CBFalconer said:
copx wrote:
>>
Do the standards say anything about size limits for string literals (min
size, max size)? I want to know this to make sure that my code is
portable. The program in question is ANSI C89, but I would also be
interested in whether or not ISO C99 changed the limits (if any exist).

Yes they do. I believe the C89/C90/C95 limit is roughly 510 bytes,
509 - not so far off...
and that C99 expanded it to roughly 1020 bytes.
....but I don't think 4095 can be plausibly called "roughly 1020".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 26 '08 #7
Richard Heathfield wrote:
CBFalconer said:
>copx wrote:
>>>
Do the standards say anything about size limits for string
literals (min size, max size)? I want to know this to make sure
that my code is portable. The program in question is ANSI C89,
but I would also be interested in whether or not ISO C99 changed
the limits (if any exist).

Yes they do. I believe the C89/C90/C95 limit is roughly 510 bytes,

509 - not so far off...
>and that C99 expanded it to roughly 1020 bytes.

...but I don't think 4095 can be plausibly called "roughly 1020".
True. However, if we express the values with logarithms, it is
only an error by a factor of 2. Trivial. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 26 '08 #8

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

Similar topics

2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
13
by: James | last post by:
consider : int main (int argc, char * argv ) { } In exec (2) ; Whose arguments which are passed to main. What is the maximum size of the string. argv = "hello........." ;
8
by: junky_fellow | last post by:
what would be the output for the following piece of code ? if ( "hello" == "hello" ) printf("True\n"); else printf("False\n"); What is the reason for that ?
23
by: Matt Garman | last post by:
Is there a clean, portable way to determine the maximum value of converted numerical fields with printf()-like functions? Doing this at compile-time would be preferable. For example, %i should...
6
by: copx | last post by:
Can you / are you supposed to free() string literals which are no longer needed? In my case I've menu construction code that looks like this: menu_items = list_new(); list_add(menu_items,...
12
by: Phil Z. | last post by:
After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot access a closed file" errors when uploading. I found a number of post on the subject and have since moved from using an...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
4
by: truezplaya | last post by:
Hello I am currently developing an application that displays information to users. I have everything working but one tiny thing thats bugging me. I create a font as below Dim I use ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.