I need a math wiz to help solve this ^^

Pages: 1234
Correct it:
From unsigned char * cp = (unsigned char *)result;
to unsigned char * cp = (unsigned char *)&result;.
It's different. Take care.
EDIT: Whoops, i did the mistake, sorry.
Last edited on
yes, that would be correct, but what about the union behaviour?
Last edited on
> I've been using the final working draft (N3337)

The C++11 FDIS is N3290, dated 2011-04-11. This was publicly available for download for a couple of weeks, before ISO pulled it back.

N3242, dated 2011-02-28 immediately preceded the draft standard and is still publicly available.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
For all practical purposes, this is all that a typical programmer would need to refer to.

N3337, dated 2012-01-16, was a working draft for the next C++ standard (presumably C++13).
The current publicly available draft is N3376, dated 2012-02-28.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.pdf



Mm.. I remember now why I settled now on 3337. The only changes made were editorial fixes.


From http://www.reddit.com/r/programming/comments/r0q78/draft_of_the_c_standard_now_officially_maintained/
sdeetee 7 points 5 days ago

Drafts go through a multi year process, during which they can change a lot. See for example the introduction, then removal, of the concepts papers to the drafts during the C++11 process.

Eventually the draft becomes a Draft International Standard (DIS) and if approved becomes a standard. ISO holds copyright over the final standards text, so the DIS text is typically only available within ISO. Then it can't be released except by ISO and affiliated standards bodies such as ANSI.

In another comment I mention that there are drafts that are very close to the standard (e.g. N3337), containing only editorial changes. But if you want to be sure that you are implementing exactly what the standard says, you'll need to get it from ISO.

You are welcome to follow along the development of the standard. Reading the papers and minutes from the WG21 site will give you more background into what's going on. Anyone can send in a paper for inclusion in the mailing. I also try to tweet from the standards meetings as much as possible to provide realtime reports of the major decisions. Finally, Herb Sutter and Michael Wong both usually have excellent trip reports.

There's a lot going on in C++ standardization. We hope to get out a standard by 2017, with drafts along the way. Implementations are starting to catch up with the standards process for a variety of reasons. Good things lie ahead!


2017!

viliml wrote:
yes, that would be correct, but what about the union behaviour?


Leaning towards no. Since neither the draft preceding the standard, nor the draft following contain the wording mentioned earlier, I would guess the actual standard does not either.

Even if it were legal, it would be something you should prefer avoiding since it introduces portability issues, whereas bitshifting does not.

> 2017!

I think ISO has a requirement that a standard has to remain stable for a minimum of five years. Probably a good thing because the compiler writers would have a lot of time to catch up and be ready by the time the next version is published.


> but what about the union behaviour?

Depends. There is no undefined behaviour with this:
1
2
3
4
5
6
7
union
{
    int v ;
    char c[ sizeof(int) ] ;
};
v = 100 ;
int i = c[0] + ( sizeof(int) > 1 ? c[1] : 0 ) ;


But this leads to undefined behaviour (an int is not permitted to alias a double):
1
2
3
4
5
6
7
union
{
    double d ;
    int v ;
};
d = 0 ;
int i = v ;


@JLBorges::Example1: What about Little/Big-Endian issues?
> What about Little/Big-Endian issues?

Yes, there is the issue of the value representation of an int - that is not undefined; it is implementation defined.

Whether an int can hold 32 bits or not is also implementation defined. To avoid dependency on implementation defined behaviour, either this:

1
2
typename std::enable_if< ( std::numeric_limits<unsigned int>::digits > 31 ), unsigned int >::type
compile_int( unsigned int, unsigned int, unsigned int, unsigned int ) ;


or this (when also the compiler would let us know if our assumption is wrong):
std::uint_fast32_t compile_int( std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t ) ;

with bitshifting, multiplication, or if a union is used, a check for endianess.

Last edited on
Topic archived. No new replies allowed.
Pages: 1234