Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

String standard

0 views
Skip to first unread message

Evyn

unread,
Oct 8, 2007, 6:03:53 AM10/8/07
to
Hi,

Can anyone tell me how C++ stores a string? I know that a double is
stored according to IEEE standard 754, sign bit, 11 bit exponent, 52
bit mantissa.

My task, essentially, is to write my own atof, so I thought I would
start with the structure of the string.

Regards (and thanks for your time),
Jim

Alf P. Steinbach

unread,
Oct 8, 2007, 6:11:45 AM10/8/07
to
* Evyn:

>
> Can anyone tell me how C++ stores a string? I know that a double is
> stored according to IEEE standard 754, sign bit, 11 bit exponent, 52
> bit mantissa.

A double is not necessarily stored according to IEEE standard.

You can use std::numeric_limits to check whether doubles are stored
according to IEEE standard with your compiler and compiler options.


> My task, essentially, is to write my own atof, so I thought I would
> start with the structure of the string.

You don't need to know the internal structure of a std::string.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Jonathan Lane

unread,
Oct 8, 2007, 7:28:10 AM10/8/07
to
On Oct 8, 11:03 am, Evyn <Evan.Dembs...@gmail.com> wrote:
> Hi,
>
> Can anyone tell me how C++ stores a string? I know that a double is
> stored according to IEEE standard 754, sign bit, 11 bit exponent, 52
> bit mantissa.
>
> My task, essentially, is to write my own atof, so I thought I would
> start with the structure of the string.

If you mean a C-style string then it's just a null terminated char
array. if you mean a C++ style string then there isn't one. There's a
string class provided by the STL but there's no guarantees on how it's
implemented. If you want an atof take a look at the lexical parser in
boost.

What's wrong with atof that you need to roll your own?

Evyn

unread,
Oct 8, 2007, 8:28:06 AM10/8/07
to

> What's wrong with atof that you need to roll your own?

Thanks for the replies.

Nothing is wrong with it, the Prof. wants us to to roll our own, thus
we roll our own :-)

osmium

unread,
Oct 8, 2007, 10:21:30 AM10/8/07
to
"Evyn" writes

> Can anyone tell me how C++ stores a string? I know that a double is
> stored according to IEEE standard 754, sign bit, 11 bit exponent, 52
> bit mantissa.
>
> My task, essentially, is to write my own atof, so I thought I would
> start with the structure of the string.


The language specification says that IEEE 754 is "normative", which is a
convoluted way of saying " we wish it were so". Also, the rules for
primitive types, such as double, are different than those for classes in the
STL, so you started with a bad analogy.

You are not supposed to know about how a string is stored. One of the
*advantages* of C++ is that it is supposed to hide such information from
you. One of the shortcomings of C++ is the usual mechanism for handling
templates is that they sometimes, as an unwanted by-product, make the
internals of a class visible.

The public interface of string is sufficient to do what you want to do.


Jonathan Lane

unread,
Oct 8, 2007, 11:27:44 AM10/8/07
to

Right. In which case as the others here have said the public interface
should be sufficient. That is to say, you can treat any sort of string
implementation should be treatable as a char array via methods on the
public interface. Take a look at c_str() on std::string for instance
or operator[]. That should give you enough to get going.

Pete Becker

unread,
Oct 8, 2007, 12:38:14 PM10/8/07
to
On 2007-10-08 04:21:30 -1000, "osmium" <r124c...@comcast.net> said:

>
> The language specification says that IEEE 754 is "normative", which is a
> convoluted way of saying " we wish it were so".

"Normative" means "required." For example, each appendix in the
standard is marked as "normative" or as "informative." There's a
section early in the standard with the title "Normative references"
which has references to other standards whose contents are
incorporated, in whole or in part, in the C++ standard. IEEE 754 is not
one of those (nor is its counterpart, IEC 559).

I couldn't find anything that says that IEE 754 is "normative." Which
part are you referring to?

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

osmium

unread,
Oct 8, 2007, 1:21:21 PM10/8/07
to
"Pete Becker" writes:

>> The language specification says that IEEE 754 is "normative", which is a
>> convoluted way of saying " we wish it were so".
>
> "Normative" means "required." For example, each appendix in the standard
> is marked as "normative" or as "informative." There's a section early in
> the standard with the title "Normative references" which has references to
> other standards whose contents are incorporated, in whole or in part, in
> the C++ standard. IEEE 754 is not one of those (nor is its counterpart,
> IEC 559).
>
> I couldn't find anything that says that IEE 754 is "normative." Which part
> are you referring to?

I can't reconstruct it, it was quite some time ago when I put that into my
head. I know my definition of "normative" came from searching through
dictionaries and such, and not from a standard. I will accept that you are
right. So it is a convoluted way of saying "required"?

I guess the bottom line is, is IEEE 754 the required representation for a
double, as the OP said?


Pete Becker

unread,
Oct 8, 2007, 1:45:13 PM10/8/07
to

Not convoluted, but formal. <g>

>
> I guess the bottom line is, is IEEE 754 the required representation for a
> double, as the OP said?

It's not required, but it has a special place. cf.
numeric_limits<Ty>::is_iec559, and the consequences of reporting true.

Default User

unread,
Oct 8, 2007, 2:48:44 PM10/8/07
to
osmium wrote:

> "Pete Becker" writes:
>
> > > The language specification says that IEEE 754 is "normative",
> > > which is a convoluted way of saying " we wish it were so".
> >
> > "Normative" means "required." For example, each appendix in the
> > standard is marked as "normative" or as "informative." There's a
> > section early in the standard with the title "Normative
> > references" which has references to other standards whose contents
> > are incorporated, in whole or in part, in the C++ standard. IEEE
> > 754 is not one of those (nor is its counterpart, IEC 559).
> >
> > I couldn't find anything that says that IEE 754 is "normative."
> > Which part are you referring to?
>
> I can't reconstruct it, it was quite some time ago when I put that
> into my head. I know my definition of "normative" came from
> searching through dictionaries and such, and not from a standard.

I don't know dictionaries you were looking at, but none of the ones I
checked say anything like what you indicate.


Brian

osmium

unread,
Oct 8, 2007, 4:29:41 PM10/8/07
to
"Default User" wrote:

>> I can't reconstruct it, it was quite some time ago when I put that
>> into my head. I know my definition of "normative" came from
>> searching through dictionaries and such, and not from a standard.
>
> I don't know dictionaries you were looking at, but none of the ones I
> checked say anything like what you indicate.

"Of, relating to or prescribing a norm or standard:_normative grammar_" (1)

I took that to mean normal, standard, usual. As in "A person normally has
two arms". A person can have only one arm and still be a person, preferably
he has two.

(1) American Heritage Dictionary


Default User

unread,
Oct 8, 2007, 5:12:48 PM10/8/07
to
osmium wrote:

I don't interpret what you've quoted in the same way you do. When
"prescribing a standard" you aren't describing what is typical, but
what is required.


Brian

James Kanze

unread,
Oct 9, 2007, 4:24:54 AM10/9/07
to
On Oct 8, 5:27 pm, Jonathan Lane <jonathan.la...@googlemail.com>
wrote:

> > Thanks for the replies.

The functions he'll doubtlessly need are those concerning
concatenation: + and += (both for string += string and string +=
char).

The prof sounds a bit sadic, however. Writing a correct
conversion (without rounding errors) to and from floating point
is extremely difficult.

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Evyn

unread,
Oct 10, 2007, 5:05:16 AM10/10/07
to

> The prof sounds a bit sadic, however. Writing a correct
> conversion (without rounding errors) to and from floating point is extremely difficult.


He can be!

Thanks for all the advice.

0 new messages