Monday, February 22, 2016

Digest for comp.lang.c++@googlegroups.com - 20 updates in 6 topics

malcolm.mclean5@btinternet.com: Feb 22 01:22PM -0800

On Monday, February 22, 2016 at 6:03:44 PM UTC, Alf P. Steinbach wrote:
 
> * For a C++11 solution you need to recursion to avoid a nasty complex
> expression. For C++14 I believe you can use a loop. I'd just use
> recursion here anyway, because it's very clear for this, and concise.
 
It's operator "".
 
Great, thanks, that's what I was looking for.
Paavo Helde <myfirstname@osa.pri.ee>: Feb 23 12:32AM +0200

On 22.02.2016 22:13, Ian Collins wrote:
>>> in the case conditions.
 
>> For values known at compile time, #define should do what you want.
 
> This is comp.lang.c++, cont comp.lang.c!
 
No problem, in C++ we can have the same:
 
enum constants: uint64_t {
Ann = 0x6e6e41,
Betty = 0x7974746542,
};
 
Or even combine this with user literals:
 
#include <iostream>
#include <string>
#include <stdint.h>
 
constexpr uint64_t operator""_id(const char* p, size_t n) {
return static_cast<unsigned char>(*p) | (n>0 ? operator""_id(p+1, n-1)
: uint64_t(0))<<8;
}
 
enum constants: uint64_t {
Ann = "Ann"_id,
Betty = "Betty"_id,
};
 
std::string StrFromId(uint64_t x) {
std::string s(reinterpret_cast<const char*>(&x), 8);
return s.substr(0, s.find(char(0)));
}
 
 
int main() {
 
uint64_t arr[] = {Ann, Betty};
 
for(auto x: arr) {
switch(x) {
case Ann:
std::cout << "A " << StrFromId(x) << "\n";
break;
case Betty:
std::cout << "B " << StrFromId(x) << "\n";
break;
}
}
}
 
Output (little-endian):
A Ann
B Betty
legalize+jeeves@mail.xmission.com (Richard): Feb 22 10:39PM

[Please do not mail me a copy of your followup]
 
Paavo Helde <myfirstname@osa.pri.ee> spake the secret code
> Ann = "Ann"_id,
> Betty = "Betty"_id,
>};
 
For this to be visible as the string "Ann\0" in memory, doesn't this
assume a certain byte order for integral types?
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Ben Bacarisse <ben.usenet@bsb.me.uk>: Feb 22 11:02PM

> print the value out as a string, and you've got a human-meaningul enumeration
> value, e.g. "charlie", "andy", "anne" and "eddie" rather than 1, 2, 3,
> 4.
 
By "print the value as a string", I suspect you mean simply treating a
pointer to the integer as a character pointer. If you want to do that,
you run into trouble with endianness if you build the value
arithmetically (as your example suggest). For little-endian machines
you need the bytes to be packed with the other significance:
 
template <typename T>
static constexpr T make_id(const char *lit, std::size_t len, T r)
{
return len ? make_id(lit, len - 1, (r << 8) + lit[len-1]) : r;
}
 
constexpr unsigned long long operator "" _id(const char *lit, std::size_t len)
{
return make_id(lit, len >= sizeof 0ULL ? sizeof 0ULL - 1 : len, 0ULL);
}
 
I have not been able to come up with a constexpr method that puts the
bytes into an integer in address order.
 
--
Ben.
"Öö Tiib" <ootiib@hot.ee>: Feb 22 03:16PM -0800

On Tuesday, 23 February 2016 01:02:37 UTC+2, Ben Bacarisse wrote:
> }
 
> I have not been able to come up with a constexpr method that puts the
> bytes into an integer in address order.
 
There are no standard trick neither in C nor in C++ to determine
endianness compile time. Any type punning is forbidden in 'constexpr'
functions. For practical purposes Boost header file endian.hpp covers
endianness for large amount of platforms.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 22 09:38PM +0100

On 22.02.2016 21:16, Jerry Stuckle wrote:
 
> Just because there wasn't an ISO standard at the time doesn't mean there
> wasn't a standard. It started with Stroustrup's book. Modifications
> followed from that.
 
I agree that Bjarne's TCPPL and later Bjarne and Margaret's ARM (the
Annotated Reference Manual) constituted the effective C++ standards at
the time, before 1998, just as Brian and Dennis' TCPL constituted the
effective C standard before C89/C90.
 
Re existence of pre 1998 namespaces, my copy of the ARM is deep down in
some unmarked box in an attic some miles from here, and likewise my copy
of Visual C++ 1.5. Yes AFAIK I still have that. But given the relatively
low accessibility of those items, and my generally vague memory, I can't
say for sure.
 
Oh, wait! Talk about bad memory, I forgot GOOGLE! Yay, Mr. Google found
the following 1994 Dr Dobbs article in zero point 38 seconds:
 
<url: http://www.drdobbs.com/cpp/c-namespaces/184409289>
 
So, this should now be regarded as solved.
 
C++ had namespaces at least as early as 1994.
 
In that article Tom Penelli refers to them as "so new [a feature]", so
presumably they were a post ARM feature. As I recall the ARM was
published in 1989. But that can of course also be checked with Mr.
Google, who knows all. :)
 
 
> standards. Nothing is further from the truth. If they come out with a
> standard, it is generally recognized world-wide. But when they haven't,
> there can still be standards.
 
Yeah, right again.
 
I remember having countless discussions about this with the late Erik
Naggum (RIP., there is a Wikipedia page about him for those unfamiliar
with the name), who insisted on very formal distinctions between formal
standard, de facto standard and so on, more shades that I don't remember
because it's never been an issue except with him. "Standard in Windows",
he cried, and would ask me to point him to the formal ISO standard that
I referred to, which of course I didn't, although now, much later, I
could point him to the 1995 ECMA standardization of the 16-bit Windows
API, I guess. Anyway. The important thing about generally useful
communication is to be understood, not to pedantically try to
misconstrue every statement. Erik was right that precision matters wrt.
technical stuff, and generally he was just right about most everything
technical. But IMHO he went too far, too rigid.
 
 
Cheers & hth.,
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: Feb 22 12:47PM -0800

On Monday, 22 February 2016 22:16:28 UTC+2, Jerry Stuckle wrote:
> standards. Nothing is further from the truth. If they come out with a
> standard, it is generally recognized world-wide. But when they haven't,
> there can still be standards.
 
Can you name the mysterious compiler? There was lot of talk of it but
nothing supported it. First C++ that gave *warning* about usage of
'namespace' as variable name was CFront 3.0.3 released May 1994. It also
did not yet have 'namespace' implemented, instead the README told that:
 
The identifier names "mutable", "namespace", and "using" will
now trigger a warning when they are used as identifiers.
For example:
 
int namespace = 37;
 
This is because they are future keywords for the ANSI C++ language
namespace feature.
Cholo Lennon <chololennon@hotmail.com>: Feb 22 05:50PM -0300

On 02/22/2016 05:38 PM, Alf P. Steinbach wrote:
> presumably they were a post ARM feature. As I recall the ARM was
> published in 1989. But that can of course also be checked with Mr.
> Google, who knows all. :)
 
Check this, namespaces are in the 1990 ARM document (is not the best
source because the ARM is not there, but the chronology could be helpful)
 
http://en.cppreference.com/w/cpp/language/history
 
 
 
--
Cholo Lennon
Bs.As.
ARG
Cholo Lennon <chololennon@hotmail.com>: Feb 22 06:09PM -0300

On 02/22/2016 05:50 PM, Cholo Lennon wrote:
 
> Check this, namespaces are in the 1990 ARM document (is not the best
> source because the ARM is not there, but the chronology could be helpful)
 
> http://en.cppreference.com/w/cpp/language/history
 
Reading again "The Design & Evolution of C++", chapter 17 "Namespaces",
Stroustroup says the following:
 
"Namespaces were voted into C++ at the Munich meeting in July 1993"

 
 
 
--
Cholo Lennon
Bs.As.
ARG
Jerry Stuckle <jstucklex@attglobal.net>: Feb 22 04:18PM -0500

On 2/22/2016 3:47 PM, Öö Tiib wrote:
 
> int namespace = 37;
 
> This is because they are future keywords for the ANSI C++ language
> namespace feature.
 
IBM's Visual C++ compiler for OS/2 and Windows did, for one. I don't
remember off hand what Linux compilers we used way back then.
 
And IIRC, even Microsoft Visual C++ 6.something supported them. But I
haven't used it for 15 years or more.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
legalize+jeeves@mail.xmission.com (Richard): Feb 22 09:20PM

[Please do not mail me a copy of your followup]
 
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code
 
>C++ had namespaces at least as early as 1994.
 
SGI's MIPSpro 7.2 compiler had them in 1995
<http://techpubs.sgi.com/library/manuals/0000/007-0704-120/pdf/007-0704-120.pdf>
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Öö Tiib" <ootiib@hot.ee>: Feb 22 01:51PM -0800

On Monday, 22 February 2016 23:19:07 UTC+2, Jerry Stuckle wrote:
> > namespace feature.
 
> IBM's Visual C++ compiler for OS/2 and Windows did, for one. I don't
> remember off hand what Linux compilers we used way back then.
 
IBM VisualAge C++ added namespace support 2003 AFAIK, at 2000 it did
have templates but no namespaces.
 
 
> And IIRC, even Microsoft Visual C++ 6.something supported them. But I
> haven't used it for 15 years or more.
 
Yes, I remember it, it had first nice IDE from MS and come shortly after
first working OS from MS (NT 4.0). It was released in 1998.
 
So how you could use those early nineties?
Jerry Stuckle <jstucklex@attglobal.net>: Feb 22 04:57PM -0500

On 2/22/2016 4:51 PM, Öö Tiib wrote:
>> remember off hand what Linux compilers we used way back then.
 
> IBM VisualAge C++ added namespace support 2003 AFAIK, at 2000 it did
> have templates but no namespaces.
 
VisualAge C++ for OS/2 and Windows didn't even exist in 2003. It had
been dropped several years before that. I don't remember exactly when,
though.
 
 
> Yes, I remember it, it had first nice IDE from MS and come shortly after
> first working OS from MS (NT 4.0). It was released in 1998.
 
> So how you could use those early nineties?
 
Visual C++ came out long before 1998.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
legalize+jeeves@mail.xmission.com (Richard): Feb 22 10:16PM

[Please do not mail me a copy of your followup]
 
Jerry Stuckle <jstucklex@attglobal.net> spake the secret code
 
>Visual C++ came out long before 1998.
 
<https://en.wikipedia.org/wiki/Visual_C%2B%2B>
 
Visual C++ 1.0 was released in 1993. The first C++ compiler was 1992.
The C compiler was introduced in 1983.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
"Öö Tiib" <ootiib@hot.ee>: Feb 22 03:09PM -0800

On Monday, 22 February 2016 23:58:17 UTC+2, Jerry Stuckle wrote:
 
> VisualAge C++ for OS/2 and Windows didn't even exist in 2003. It had
> been dropped several years before that. I don't remember exactly when,
> though.
 
OS/2 was long dead indeed but that VisualAge crap did still smoulder
here and there. At 2000 its C++ certainly did not have namespaces. I trust
it was 2011 when VisualAge was finally dropped and replaced with
XL C/C++ by IBM.
 
> > first working OS from MS (NT 4.0). It was released in 1998.
 
> > So how you could use those early nineties?
 
> Visual C++ came out long before 1998.
 
Yes, looked it up https://support.microsoft.com/en-us/kb/145669 it
seems that Visual C++ 4.00 were first that had namespaces (released at
end of 1995). Borland C++ 5.0 released 1996 had also namespaces. So
those were impossible to use in the early 90's without time machine.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 22 07:43PM

On 22/02/2016 08:43, David Brown wrote:
 
> In most cases, of course, the benefit of extended identifiers is for
> non-English language programmers to be able to use identifiers in their
> own language - typing with their normal keyboard layout.
 
Feel free to name one country that doesn't use Arabic numerals or the
asterisk or equals sign. To square a number:
 
r = n * n;
 
/Flibble
Paavo Helde <myfirstname@osa.pri.ee>: Feb 22 11:24PM +0200

On 22.02.2016 21:43, Mr Flibble wrote:
 
> Feel free to name one country that doesn't use Arabic numerals
 
Why, that's Arabia of course :)
 
Eastern Arabic ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩
 
Perso-Arabic variant ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
 
Urdu variant ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 22 08:21PM

On 22/02/2016 20:19, Ian Collins wrote:
 
>> I do hope you are writing that whilst saying it out loud in Stewie
>> Griffin's voice.
 
> Who?
 
https://www.youtube.com/watch?v=NTSGp4UdEvQ
 
/Flibble
ram@zedat.fu-berlin.de (Stefan Ram): Feb 22 02:42AM

>};
>If so, is there a reference in the "standard" that grants this
>permission, and when did this syntax come about?
 
When an object of the above class is being default-initialized,
its constructor is called with an empty argument list (9.5p7).
 
Then, according to 12.6.2p9, »In a non-delegating
constructor« (9.1), »if the entity is a non-static data
member that has a brace-or-equal-initializer« ...
»the entity is initialized as specified in 8.5;«.
 
8.5p17.8 then says, »the initial value of the object being
initialized is the (possibly converted) value of the
initializer expression.«
"Öö Tiib" <ootiib@hot.ee>: Feb 21 05:09PM -0800

On Monday, 22 February 2016 00:31:09 UTC+2, Chris M. Thomasson wrote:
> #include <vector>
> #include <climits>
> #include <cassert>
 
It likely makes sense to turn on FENV_ACCESS and (further) make sure that
floating point environment is same on encrypting and decrypting side
 
#pragma STDC FENV_ACCESS ON
 
etc. Modern compilers sometimes cause major headache without.
 
 
> typedef double iim_float_t;
> typedef std::complex<iim_float_t> complex_t;
> typedef std::array<bool, CHAR_BIT> bitchar_t;
 
I would consider 'std::bitset<CHAR_BIT>' here because it has semantics
of bool array plus number of handy methods. You are seemingly
manufacturing some yourself. Can't compare performance here since
amounts of standard output in code but it is highly competitive
container of bools wherever I have used it.
 
> }
> __________________________________________________
 
> What do you think of this?
 
The 128 bit key looks small, I'm not expert enough to consider its
potential vulnerabilities otherwise.
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: