473,320 Members | 1,951 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,320 software developers and data experts.

const c string in data section?

hi,

i am using an IAR embedded c compiler. some times when i run out of
the overall data segment
capacity, i found i can reduce the data segment usage by simply
removing some kind of statements such as below,

printf( "hello, %d\n", 100 )

it seems tell me that "hello, %d\n" was allocated in data segment.
but for the compiler, read only data should be put in code segment
rather than data segment. so, i thing my question should be: is the
"hello, %d\n" really a kind of READ ONLY data?

thanks.

-
woody

Jul 10 '07 #1
3 1981
In article <11**********************@j4g2000prf.googlegroups. com>,
Steven Woody <na********@gmail.comwrote:
>i am using an IAR embedded c compiler. some times when i run out of
the overall data segment
capacity, i found i can reduce the data segment usage by simply
removing some kind of statements such as below,
>printf( "hello, %d\n", 100 )
>it seems tell me that "hello, %d\n" was allocated in data segment.
but for the compiler, read only data should be put in code segment
rather than data segment. so, i thing my question should be: is the
"hello, %d\n" really a kind of READ ONLY data?
String literals are allowed to be read-only, and to the extent
that "code vs data" can be meaningfully talked about within the
C standard, they are data rather than code (e.g., they are
objects not function pointers). But string literals are not -required-
to be read-only; your particular compiler might have a compiler
option to choose one behaviour or another.
--
Prototypes are supertypes of their clones. -- maplesoft
Jul 10 '07 #2
Eric Sosman <Er*********@sun.comwrote:
There used to
be a program called xstr that would do a transformation
much like this one, but IIRC it botched some "unusual"
usages.
<ot>It seems to be alive and well on this public NetBSD machine, so
perhaps it would be more appropriate to speak of the application in
the present tense.</ot>

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 10 '07 #3
Steven Woody wrote:
>
i am using an IAR embedded c compiler. some times when i run out
of the overall data segment capacity, i found i can reduce the
data segment usage by simply removing some kind of statements such
as below,

printf( "hello, %d\n", 100 )

it seems tell me that "hello, %d\n" was allocated in data segment.
but for the compiler, read only data should be put in code segment
rather than data segment. so, i thing my question should be: is
the "hello, %d\n" really a kind of READ ONLY data?
Yes, but the compiler is mad. There is no reason the string cannot
be kept in the "data seqment", whatever that may be.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

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

Jul 11 '07 #4

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

Similar topics

10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
6
by: michaelkatsilis | last post by:
Hi, Are there any issues with returning a const reference value for public "get" accessor methods? eg. const string & getVal(); // or const MyString & getVal();
15
by: Dave | last post by:
Hello NG, It is well known that memory-allocating definitions should not be put in a header file. I believe, however, that this does not apply to const definitions. For example: #ifndef...
11
by: Paul Emmons | last post by:
In writing a function similar to strstr(), I'm calling both of the arguments "const char *". My compiler (gcc) complains "warning: return discards qualifiers from pointer target type" unless I...
5
by: LaBird | last post by:
Dear all, I'd like to ask for the following C code segment: #include <stdio.h> int main() { char *a = "abc"; /* Line 1 */ printf("%s", a); /* Line 2 */ a = '1'; /* Line...
2
by: Pavel | last post by:
I am writing software for an embedded application and here is the question. GCC would emit data declared like const char text = "abc"; to .rodata (i.e. "read only data") section. I can put this...
0
by: KarenS | last post by:
I am using Microsoft Developer Environment 2003 Version 7.1.3088 and .NET Framework version 1.1.4322 SP1. From my web-service I get one row of data and return it to my client. From my client I...
4
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile...
15
by: Jiří Paleček | last post by:
Hello, I know the rules for const handling in C++, but I'd like to ask what is the "right" way to use them, eg. when is it appropriate to make a member function const? This came across this...
10
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.