Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > memory for string literals

Reply
Thread Tools

memory for string literals

 
 
Tim Prince
Guest
Posts: n/a
 
      12-20-2009
happy wrote:
> On Dec 20, 8:46 am, Gareth Owen <(E-Mail Removed)> wrote:
>> happy <(E-Mail Removed)> writes:
>>> So does that mean that if we count all the characters (printf
>>> strings,scanf strings and string literals declared like char
>>> *a="hello"),
>>> it shouldn't be more than 4095?

>> No. 4095 per string literal.

>
> I asked this question in a c community and someone replied that it is
> related to virtual addressing.
> How it is related to virtual addressing?

Did someone misquote? The original limit may be related to addressing
modes used on some machine in the distant past. The 509 character per
string limit of C89 looks like an IBM360 sort of limitation.
 
Reply With Quote
 
 
 
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      12-21-2009
On Dec 20, 3:59*am, Antoninus Twink <(E-Mail Removed)> wrote:
> Firstly, please ignore the trolls in this group. The 4095 figure is
> entirely theoretical. In practice on all current real-world compilers,
> string literals can be as big as you want - the only limitation is the
> amount of memory available to store them.



To clarify, many compilers have limits on the size of a single string
literal, while allowing many to be defined and the total size of the
string literal pool to be a large fraction of the available space.
For example, MSVC allows 65535 byte string literals, after
concatenation of adjacent string literals (individual string literals
can be up to 2048 bytes). Although you can store many of those.
 
Reply With Quote
 
 
 
 
David Thompson
Guest
Posts: n/a
 
      01-07-2010
On Sun, 20 Dec 2009 06:30:19 -0800, Tim Prince
<(E-Mail Removed)> wrote:

> happy wrote:
> > On Dec 20, 8:46 am, Gareth Owen <(E-Mail Removed)> wrote:
> >> happy <(E-Mail Removed)> writes:
> >>> So does that mean that if we count all the characters (printf
> >>> strings,scanf strings and string literals declared like char
> >>> *a="hello"),
> >>> it shouldn't be more than 4095?
> >> No. 4095 per string literal.

> >
> > I asked this question in a c community and someone replied that it is
> > related to virtual addressing.
> > How it is related to virtual addressing?

> Did someone misquote? The original limit may be related to addressing
> modes used on some machine in the distant past. The 509 character per
> string limit of C89 looks like an IBM360 sort of limitation.


The S/360 limitation (MVC etc.) would be 255.

512 was the PDP-11 disk sector size and (thus) early Unix filesystem
block size. For I/O-ly things like output-per-conversion-specifier
and maybe sourceline-size 509 would make sense as 512-slop;
but BUFSIZ can be 256 and textfile linesize 254 = 256-slop.

And a string literal _before_ concatenation is standardly limited by
sourcefile linesize. But since a main point of concatentation is to
relax that limit, I would expect it not to apply _after_.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java: byte literals and short literals John Goche Java 8 01-17-2006 11:12 PM
Unicode String Literals didster@gmail.com Java 4 11-21-2005 11:43 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
character literals and string Pete Elmgreen Java 3 11-24-2004 04:42 PM
String literals in Java Harri Pesonen Java 59 06-02-2004 08:00 PM



Advertisments