Thursday, December 8, 2016

Digest for comp.lang.c++@googlegroups.com - 25 updates in 5 topics

ruben safir <ruben@mrbrklyn.com>: Dec 07 11:23PM -0500

On 12/07/2016 05:59 PM, David Brown wrote:
> would simply use a pre-written png library.
 
 
thats 100% true. But along with that means I would do a huge research
first through the dozen C++ and PNG texts I have and a duckduckgo
search, BEFORE posting.
ruben safir <ruben@mrbrklyn.com>: Dec 07 11:24PM -0500

On 12/07/2016 05:59 PM, David Brown wrote:
> clear enough explanation about what endianness means,
 
 
no, it doesn't. Maybe you can reedit it.
Robert Wessel <robertwessel2@yahoo.com>: Dec 08 12:01AM -0600

On Wed, 7 Dec 2016 23:24:35 -0500, ruben safir <ruben@mrbrklyn.com>
wrote:
 
>On 12/07/2016 05:59 PM, David Brown wrote:
>> clear enough explanation about what endianness means,
 
>no, it doesn't. Maybe you can reedit it.
 
 
As a regular WP editor (although I don't believe I've ever edited that
particular article), I may be biased, but it looks like a pretty good
article to me. Clear, concise, complete and well referenced - you
really can't ask for much more (the article's "B" class rating
suggests that I'm not the only one with that opinion). The basic
concept is explained in the first introductory paragraph, and then
nicely illustrated in two illustrations in the immediately following
"Illustration" section.
 
OTOH, I do know what endianness is, which may be leading me to making
incorrect assumptions about the context in which someone without that
knowledge would be reading the article, leading to some significant
omitted information. If you have some constructive criticism
regarding how the article failed you, I can certainly take a look at
improving it.
Gareth Owen <gwowen@gmail.com>: Dec 08 07:26AM


> On 12/07/2016 05:59 PM, David Brown wrote:
>> clear enough explanation about what endianness means,
 
> no, it doesn't. Maybe you can reedit it.
 
Maybe the problem is not with the article? Try this one.
https://simple.wikipedia.org/wiki/Endianness
Paavo Helde <myfirstname@osa.pri.ee>: Dec 08 10:08AM +0200

On 8.12.2016 9:26, Gareth Owen wrote:
 
>> no, it doesn't. Maybe you can reedit it.
 
> Maybe the problem is not with the article? Try this one.
> https://simple.wikipedia.org/wiki/Endianness
 
"For each hard question there is a simple, easily understandable wrong
answer" - except that this article is IMO wrong, but still not easily
understandable. What is "hexadecimal data"? Is AB12 really encoded in 4
bits?
 
Why they want to couple endianness with some binary data representation?
In a "simple pedia" like that I would stick to our common decimal
representation and just say that the number ten is written by two
digits: 0 and 1, which can be ordered either as 01 or 10. I also would
talk something about Gulliver and about the egg-eater wars and who has won.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 08 09:32AM +0100

On 08.12.2016 09:08, Paavo Helde wrote:
> representation and just say that the number ten is written by two
> digits: 0 and 1, which can be ordered either as 01 or 10. I also would
> talk something about Gulliver and about the egg-eater wars and who has won.
 
Not everybody knows that Jonathan Swift wrote the original
recursion-poem, that Augustus De Morgan based his more well-known
variant on. So, first of all, Jonathan Swift → Augustus De Morgan.
 
Then there's the connection George Boole ← (friendly
article/book-publishing competitor with) Augustus DeMorgan → (private
math tutor to) Lady Augusta Ada → (coder and sort of secretary for)
Charles Babbage → first general programmable computer.
 
I remember getting almost angry when some American professor wrote an
article about the history of computers in Scientific American, and
managed to omit all that crucial English history. He started with
something about Napoleon, skipped the German/English part entirely, and
ended with the US developments after WWII. I think he even managed to
omit that John von Neumann was Hungarian, like, he was an American.
 
Not sure how much of this to include in an article about endianness, though.
 
But it would be nice with a discussion of the endianness of Babbage's
analytical engine.
 
 
Cheers!,
 
- Alf
Jorgen Grahn <grahn+nntp@snipabacken.se>: Dec 08 11:41AM

On Wed, 2016-12-07, David Brown wrote:
 
> That /might/ be acceptable, assuming you have control of aligned or
> unaligned accesses, as well as aliasing issues.
 
>> then byteswap it:
 
Here he also has to know he's on a little-endian machine, and with
certain compilers. IMO, a high price to pay to avoid byte-level
reads.
 
There is ntohl() if you're on Unix.
 
> that you are happy to jump straight to an endianness swap routine. But
> one step at a time is best until the OP is confident in what he is doing
> here.
 
Yes. Part of the point with my get_bigendian32() above is that it
shows[0] that there /are/ no 32-bit integers in binary files, not in
the C++ sense. There are just bytes, and your code is responsible for
the conversion (according to the rules set by whoever created the file
format).
 
/Jorgen
 
[0] Slightly exaggerated, perhaps.
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
legalize+jeeves@mail.xmission.com (Richard): Dec 08 06:02PM

[Please do not mail me a copy of your followup]
 
Paavo Helde <myfirstname@osa.pri.ee> spake the secret code
>answer" - except that this article is IMO wrong, but still not easily
>understandable. What is "hexadecimal data"? Is AB12 really encoded in 4
>bits?
 
What is hexadecimal data? Seriously? Are you unable to google or
use WP's search box?
 
Never mind that "hexadecimal" is linked right in the article.
 
Nowhere in that article could I find the data 0xAB12.
 
>Why they want to couple endianness with some binary data representation?
 
Because the discussion of endianness is meaningless without
discussing how things are stored as binary values in memory or on a
communication stream.
 
If you don't care how things are stored or transmitted in some binary
form, then you don't care about endianness.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
BGB <cr88192@hotmail.com>: Dec 08 12:24PM -0600

On 12/8/2016 5:41 AM, Jorgen Grahn wrote:
> certain compilers. IMO, a high price to pay to avoid byte-level
> reads.
 
> There is ntohl() if you're on Unix.
 
it also exists on Windows if using Winsock.
though, it is not as good, as it is a function call into a DLL, so
faster options are possible.
 
 
>> that you are happy to jump straight to an endianness swap routine. But
>> one step at a time is best until the OP is confident in what he is doing
>> here.
 
those are not exactly portable options though.
 
also possible could be:
uint32 bswap32(uint32 v0)
{
uint32 v1, v2;
v1=((v0&0xFF00FF00U)>> 8)|((v0&0x00FF00FFU)<< 8);
v2=((v1&0xFFFF0000U)>>16)|((v1&0x0000FFFFU)<<16);
return(v2);
}
 
with more specialized options based on combination of arch and compiler.
 
 
> the C++ sense. There are just bytes, and your code is responsible for
> the conversion (according to the rules set by whoever created the file
> format).
 
yep.
 
file formats get fun, endianess is variable, non-power-of-2 integer
sizes are common, bitstreams are also common (with multiple variations
thereof), ...
 
 
wrote various stuff about having multiple variations of an LZ compressed
bitstream format intended for large numbers of small buffers (where
minimizing constant factors becomes a bigger issue), but decided to
leave this out as it drifts a bit far from the topic at hand.
 
but, yes, entropy coded bitstreams are also fun...
Paavo Helde <myfirstname@osa.pri.ee>: Dec 08 09:30PM +0200

On 8.12.2016 20:02, Richard wrote:
>> bits?
 
> What is hexadecimal data? Seriously? Are you unable to google or
> use WP's search box?
 
Tell me, what is "hexadecimal data"? I can understand what is
"hexadecimal representation of data", but "hexadecimal data"? If a
weather station reports temperature 25°C, is this "hexadecimal data" or not?
 
 
> Nowhere in that article could I find the data 0xAB12.
 
Are you sure you looked at the same article?
https://simple.wikipedia.org/wiki/Endianness
 
It appears user Dearingj has changed 'bits' to 'pieces' today, so maybe
all my nitpicking is not in vain ;-)
 
Cheers
Paavo
Gareth Owen <gwowen@gmail.com>: Dec 08 08:00PM

> "hexadecimal representation of data", but "hexadecimal data"? If a
> weather station reports temperature 25°C, is this "hexadecimal data"
> or not?
 
You are technically correct, the best sort of correct.
 
However, you *don't* really not understand what "hexadecimal data"
means, you're just being an annoying pedant.
 
Pedantry and simplicity are often at odds. Can you guess which way
Simple Wikipedia tends to lean?
Christian Gollwitzer <auriocus@gmx.de>: Dec 08 09:36PM +0100

Am 08.12.2016 um 21:00 schrieb Gareth Owen:
> Pedantry and simplicity are often at odds. Can you guess which way
> Simple Wikipedia tends to lean?
 
Maybe, but that particular article is both not simple and incorrect.
A) Not simple: The second sentence has nested parataxes (indicated by
brackets)
 
"In computer coding, certain numbers, [usually two bytes long (1 byte
= 8 bits) [ that are called "words",] ] can be written or input in two ways"
 
B) Incorrect: It says that the number 0x12AB in big endian is 12|AB,
because "the bigger number comes at the end", explaining the hexadecimal
digits 0..9A..F. So it is big endian, because AB > 12 ? I can't seem to
understand the sentence in the correct way, it is definitely incorrect
 
 
Christian
Paavo Helde <myfirstname@osa.pri.ee>: Dec 08 10:40PM +0200

On 8.12.2016 22:00, Gareth Owen wrote:
> means, you're just being an annoying pedant.
 
> Pedantry and simplicity are often at odds. Can you guess which way
> Simple Wikipedia tends to lean?
 
That's what I said, "simple and wrong". The notion of 'endianness' and
the notion of 'data' have nothing whatsoever to do with 'hexadecimal',
so why the Wikipedia article starts with "Endianness refers to how
hexadecimal data is ordered ..."?
 
I can understand that people like simple and wrong explanations. I just
don't approve it. But in this case, I feel that 'hexadecimal' is
actually complicating the things, instead of making them simpler. This
article should not contain 'hexadecimal' at all.
 
Cheers
Paavo
Andrey Karpov <karpov2007@gmail.com>: Dec 08 10:02AM -0800

We released the PVS-Studio analyzer for Linux. Now Linux developers are getting a new powerful tool to fight bugs in the code.
 
http://www.viva64.com/en/b/0441/
"Öö Tiib" <ootiib@hot.ee>: Dec 07 11:25PM -0800

On Thursday, 8 December 2016 00:00:24 UTC+2, Christian Steins wrote:
 
> Ok, and by checking rd.entropy() I can find out if it's a real random
> device (entropy > 0) or not.
 
> In my case it returns 0.
 
If you want slightly less predictable seeds than time then Windows API
contains a CryptGenRandom function.
Christian Steins <cs01@quantentunnel.de>: Dec 08 10:09AM +0100

Am 08.12.2016 um 08:25 schrieb Öö Tiib:
 
>> device (entropy > 0) or not.
 
> If you want slightly less predictable seeds than time then Windows API
> contains a CryptGenRandom function.
 
Thanks, but this is not portable.
 
Yesterday I tested:
 
unsigned int seed; // uninitialized stack variable
seed = seed + reinterpret_cast<size_t> (&seed); // add it's address
seed = seed + time(0); // add current time
 
Very ugly, but it works.
 
Christian
Ben Bacarisse <ben.usenet@bsb.me.uk>: Dec 08 11:28AM


> unsigned int seed; // uninitialized stack variable
> seed = seed + reinterpret_cast<size_t> (&seed); // add it's address
> seed = seed + time(0); // add current time
 
The fact that seed is a stack variable suggests that you are re-seeding
the generator with every call. That's going to undo all the good work
the authors of the generator put in to make the results pseudo-random.
 
You might want to consider using a high-resolution timer from
std::chrono.
 
--
Ben.
"Öö Tiib" <ootiib@hot.ee>: Dec 08 03:30AM -0800

On Thursday, 8 December 2016 11:09:32 UTC+2, Christian Steins wrote:
 
> > If you want slightly less predictable seeds than time then Windows API
> > contains a CryptGenRandom function.
 
> Thanks, but this is not portable.
 
When there are no portable solutions then it is usually good idea to
look for platform-specific solutions.
 
> seed = seed + reinterpret_cast<size_t> (&seed); // add it's address
> seed = seed + time(0); // add current time
 
> Very ugly, but it works.
 
That I would not use. Lot of undefined behaviors seem to work
until most embarrassing situation. Next version of gcc may
optimize it into 'unsigned int seed = 42;' and that may cause
major stakeholder to lose pile of money. Who to blame?
Ben Bacarisse <ben.usenet@bsb.me.uk>: Dec 08 12:48PM


> so as to shift some of the variation from the least-
> significant digits of the time to some more significant
> digits of the result.
 
And thereby introducing some predictable structure into the seed (for
example the bottom bit in now known with high probability). What
evidence so you have that is generally a good thing to do?
 
 
> to throw away the first values of »rand()«
> which might be related to the seed in an
> obvious manner.
 
That seems odd too. The all of the values of std::rand() are probably
related to the seed in an obvious way. They certainly are in the case
being discussed.
 
> We now have ::std::filesystem, and it might be possible
> to get some entropy from there (for example, from struct
> space_info).
 
Presumably it's optional. Is there a portable way to test if it's
available?
 
--
Ben.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 08 02:30PM +0100

On 08.12.2016 14:07, Stefan Ram wrote:
> 5811, 5912, and 5984. The multiplication will make
> this obvious correlation disappear (under many
> implementations).
 
You're seeing the time values. Just advance the generator one number.
Successive pseudo-random numbers have no easily discernible relation to
each other.
 
 
 
> In the course room, the participiants are always like,
> "But those values all are near to each other!«, and I
> want to show them that it is possible to change this.
 
I recommend Knuth's "The Art of Computer Programming", I think it was vol I.
 
Well, that's the only book about random generators I can recommend,
because it's they only one I've read. :)
 
 
Cheers & hth.,
 
- Alf
Ben Bacarisse <ben.usenet@bsb.me.uk>: Dec 08 03:33PM

>>example the bottom bit in now known with high probability). What
>>evidence so you have that is generally a good thing to do?
 
> I did not claim that it is /generally good/.
 
OK, but that was very far from clear. I tried, wherever possible, to
show general solutions in the classroom so it seemed to me you might be
showing this because you think it is generally a good idea.
 
> they can exert some control over it. I do not claim
> that this is generally a good thing - generally one would
> not use »::std::rand()« at all!
 
One should not used rand if it's that bad. There's nothing wrong with
using it if your library has a good implementation.
 
 
> In the course room, the participiants are always like,
> "But those values all are near to each other!«, and I
> want to show them that it is possible to change this.
 
There is another good teaching point here -- beware of replacing an
obvious correlation with a non-obvious correlation. In some situations
the latter is more dangerous because it might hide the use of bad
generator.
 
--
Ben.
ram@zedat.fu-berlin.de (Stefan Ram): Dec 08 11:43AM

>the authors of the generator put in to make the results pseudo-random.
>You might want to consider using a high-resolution timer from
>std::chrono.
 
What I show in the classroom is:
 
::std::srand
( ::std::time( 0 )* ::std::time( 0 )+ ::std::time( 0 ));
 
so as to shift some of the variation from the least-
significant digits of the time to some more significant
digits of the result. And then
 
::std::rand(); ::std::rand(); ::std::rand();
 
to throw away the first values of »rand()«
which might be related to the seed in an
obvious manner.
 
We now have ::std::filesystem, and it might be possible
to get some entropy from there (for example, from struct
space_info).
ram@zedat.fu-berlin.de (Stefan Ram): Dec 08 01:07PM

>And thereby introducing some predictable structure into the seed (for
>example the bottom bit in now known with high probability). What
>evidence so you have that is generally a good thing to do?
 
I did not claim that it is /generally good/.
But when one just does
 
::std::srand( ::std::time( 0 )); ::std::cout << ::std::rand();
 
, one can see that the value printed one second later
(when the whole program is being started anew)
is near to the value printed one second earlier.
E.g., subsequent runs of the program might print
5811, 5912, and 5984. The multiplication will make
this obvious correlation disappear (under many
implementations).
 
The above multiplication makes this effect disappear
/in the course room/ so the participiants can see that
they can exert some control over it. I do not claim
that this is generally a good thing - generally one would
not use »::std::rand()« at all!
 
>That seems odd too. The all of the values of std::rand() are probably
>related to the seed in an obvious way.
 
It has the same effect of making the obvious correlation
go away.
 
In the course room, the participiants are always like,
"But those values all are near to each other!«, and I
want to show them that it is possible to change this.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 08 12:57AM +0100

On 07.12.2016 22:52, Daniel wrote:
> }
 
> Instantiating A<SomeTraits> results in "syntax error: '<'" for both (1) and (2).
> Is that expected?
 
Yes.
 
You have to tell the compiler about dependent names when they're types
(you've done that, added `typename`) and when they're templates (need to
add `template`):
 
template <class Traits>
struct A
{
typedef typename Traits::template vec<int> v1_t; // (1)
using v2_t = typename Traits::template vec<int>; // (2)
};
 
Cheers & hth.,
 
- Alf
Daniel <danielaparker@gmail.com>: Dec 07 06:41PM -0800

On Wednesday, December 7, 2016 at 7:00:57 PM UTC-5, Alf P. Steinbach wrote:
> You have to tell the compiler about dependent names when they're types
> (you've done that, added `typename`) and when they're templates (need to
> add `template`):
 
Thanks!
Daniel
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: