Wednesday, May 31, 2023

Digest for comp.lang.c++@googlegroups.com - 1 update in 1 topic

Muttley@dastardlyhq.com: May 31 07:38AM

On Tue, 30 May 2023 20:31:10 +0200
>internet memes about how hard it is to learn Finnish.
 
>Still, I think if you live in a different country it is important to try
>to learn the language, even if you never really master it.
 
Completely agree. I've spent the last 10 years relearning french after
a 20 year gap from school and I know I'll never be fluent in it but I can
get by in conversation and I'm quite good at reading. If you make the effort
you get the results.
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.

Friday, May 26, 2023

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

"R.Wieser" <address@is.invalid>: May 26 09:07AM +0200

Paavo,
 
> I'm using a native socket created by the C socket() call.
 
I've got one bit of code using a native socket (ws2_32.dll). But it what I
would like to be able to do without. Just OpenSSL calls - preferrably just
SSL_xxx family calls, but opening a simple native socket using BIO_xxx would
be acceptable (iow : not using the BIO_new_ssl_connect and related ones).
 
> Right. Nobody has said life should be easy ;-)
 
Whut ?! I'm sure I've said that a few times in the past .... :-p
 
> Also, nobody has paid me to prepare code examples which would exactly suit
> your needs.
 
I can't vouch for that, but it is why I started this thread. I can google
snippets of OpenSSL code easily. The problem for me is learning how they
work - so that I have a fighting chance to combine them in new, interresting
ways.
 
Did I already mention that I'm a hobby programmer, who, as part of that
hobby, doesn't have a problem with spending time on trying to figure stuff
out ? Well, I am and I don't. :-)
 
> You just snipped the code which you maybe will try to figure out in the
> future.
 
I just stored the code samples which mention doing that for future use, in
current favor of some of the more basic code samples.
 
Though in this particular case there is a "maybe" involved. There is a good
chance that I will try to keep the whole thing self-contained. On the other
hand, there is also a good chance that I will make the use of that external
storage available depending on a (commandline) setting.
 
> For openssl functions, you can at least just google "man FUNCTIONNAME" to
> get the man page.
 
Thats what I've been pretty-much doing, and finding stuff like
 
https://www.openssl.org/docs/man1.1.1/man3/SSL_connect.html
 
That site seems to be a nice source for function reference. But just take a
look at the difference of information between the blocking and non-blocking
usage (remember that I mentioned that I'm using, for starters,using the
simpler "blocking" mode ?).
 
Another one :
 
https://www.openssl.org/docs/manmaster/man3/SSL_set_fd.html
 
Its good enough when you want to look up something (looking back), but isn't
as good when you need a usage explanation (looking forward).
 
Ahhh.... I already wondered why I have been using SSL_set_fd and BIO_get_fd
(digging down to the native socket), while not having seen anything which
loads the BIO directly into the SSL context.
 
It turns out that that function actually exists : SSL_set_bio. Now all I
have to do is to spend (heaps of) time googeling for that function, in the
hope I can find some code using it (showing how the BIO needs to be
created).
 
> Of course, it does not help openssl contains hundreds of functions, half
> of which are deprecated, and half of which are not needed for the task at
> hand.
 
:-) You noticed. ssleay32.dll has (just) 206. libeay32.dll has a whopping
2953 of them.
 
Yeah, thats part of the problem I'm having with OpenSSL. It seems to have
multiple ways of reaching the same goal (take BIO_read and SSL_read. No
real idea when either is (in)valid to use), and than finding examples which
mix the different methods does not help me in getting the big picture. :-|
 
> If one feels uncomfortable with raw sockets
 
I've got no problem with that (see below).
 
> and raw openssl,
 
And that is what I would like to do - but *not* mixing raw sockets up with
"raw" OpenSSL.
 
Although I have code available which does all of the "raw" / native socket
handling (parsing the host : port combination, resolving the host to an IP,
connecting to that IP and port), I cannot escape the feeling that
/somewhere/ in that humongous ammount of ssleay32 and libay32 functions
there must be functions which offer the same - but than in a simpler
package.
 
Actually, BIO_set_conn_hostname does the parsing just fine, but not at the
level I would like to see it happening (using the SSL_xxx environment).
 
By the way : I posted here because this is where I expected the most chance
of getting a "low level" answer (the "comp.lang.c" newsgroup seems to have
been poisonned by spammers). I'm actually using an Assembler (Borlands
Tasm32), which goes even lower than that. :-)
 
Regards,
Rudy Wieser
Paavo Helde <eesnimi@osa.pri.ee>: May 26 11:35PM +0300

26.05.2023 10:07 R.Wieser kirjutas:
 
> snippets of OpenSSL code easily. The problem for me is learning how they
> work - so that I have a fighting chance to combine them in new, interresting
> ways.
 
Suggesting you to post these questions to the openssl-users@openssl.org
mailing list (subscribe at
https://mta.openssl.org/mailman/listinfo/openssl-users), there are
people who know infinitely more about openssl than myself. If your use
case is not the exact same than mine then I'm afraid I can not be of
much help.
Vir Campestris <vir.campestris@invalid.invalid>: May 26 08:49PM +0100

On 23/05/2023 15:51, Scott Lurndal wrote:
> drive and the disk controller, allowing eight controllers to
> simultaneously transfer data to/from memory (interleaved with
> processor accesses to the same memory).
 
My experience was ICL 2900s, and AIUI they could have multiple memory
subsystems. Moving data between them was something we did our ****est to
avoid.
 
Andy
"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu>: May 26 12:49AM -0700

> "james...@alumni.caltech.edu" <james...@alumni.caltech.edu> wrote:
> >On Wednesday, May 24, 2023 at 4:51:07=E2=80=AFAM UTC-4, Mut...@dastardlyhq.=
> >com wrote:
...
> cut and pasted properly but it still failed.
 
> However this wouldn't be the first time the Apple version of Clang differs
> from versions on other platforms.
 
Something about that error message makes me suspicious that the
problem may be more fundamental. Does it still complain if you change it
to use a raw pointer, rather than a shared_pointer?:
 
mystruct(*sp)[3](new mystruct[1][3]);
...
for(auto &ms: sp[0]) ms.func();
...
delete[] sp;
Muttley@dastardlyhq.com: May 26 08:44AM

On Fri, 26 May 2023 00:49:32 -0700 (PDT)
>for(auto &ms: sp[0]) ms.func();
>....
>delete[] sp;
 
No, that compiles fine. Looks like the current Mac version of Clang does
have a bug but given how infrequently Apple updates their compiler I won't
hold my breath on it being fixed anytime soon.
Bonita Montero <Bonita.Montero@gmail.com>: May 26 01:14PM +0200


> No, that compiles fine. Looks like the current Mac version of Clang does
> have a bug but given how infrequently Apple updates their compiler I won't
> hold my breath on it being fixed anytime soon.
 
AFAIK you can replace Apple's clang with LLVM clang somhehow.
"Öö Tiib" <ootiib@hot.ee>: May 26 05:59AM -0700

On Friday, 26 May 2023 at 14:16:10 UTC+3, Bonita Montero wrote:
> > have a bug but given how infrequently Apple updates their compiler I won't
> > hold my breath on it being fixed anytime soon.
> AFAIK you can replace Apple's clang with LLVM clang somhehow.
 
Yes, <https://releases.llvm.org/> can download distributions for Apple too.
Muttley@dastardlyhq.com: May 26 03:00PM

On Fri, 26 May 2023 05:59:02 -0700 (PDT)
 
>> > hold my breath on it being fixed anytime soon.
>> AFAIK you can replace Apple's clang with LLVM clang somhehow.
 
>Yes, <https://releases.llvm.org/> can download distributions for Apple too.
 
Every new release of MacOS locks things down more and more. I'm a bit
paranoid about updating something as fundamental as the compiler and all
the libraries as I have a nasty feeling things might die halfway through with
some system integrity or unsigned code error or similar.
Bonita Montero <Bonita.Montero@gmail.com>: May 26 07:20PM +0200

> paranoid about updating something as fundamental as the compiler and
> all the libraries as I have a nasty feeling things might die halfway
> through with some system integrity or unsigned code error or similar.
 
I think a compiler is much more fundamental for Linux than for macOS.
Muttley@dastardlyhq.com: May 26 08:40AM

On Thu, 25 May 2023 20:49:28 +0200
>highly knowledgeable and totally naïve. They need patient teachers and
>"parents", working with them for many years at least, and no one is
>willing to wait for that.
 
Sure, but like a lot of people you're missing the point. It doesn't matter
if the data its trained on is out of date or just pure rubbish, its the fact
that it somehow comprehends it and can make links between unrelated topics.
 
Plenty of very smart people in the past have argued about how many angels
can fit on the head of a pin because of the nonsense in religious story books,
that doesn't mean they're thick.
Muttley@dastardlyhq.com: May 26 08:42AM

On Thu, 25 May 2023 20:58:41 +0200
>But it appears to have been done by making up a poem about C++ in modern
>English (no mean feat in itself), then translating word for word where
>the system could find a Middle English equivalent (with no regard for
 
The fact that it can do it at all is amazing to me.
 
>can understand most of the poem. But if you look up some Chaucer or
>other real Middle English poetry, I doubt you'll have much idea at all
>about what it is saying - at least not without a lot of effort.
 
Chaucer can be understandable , often its a modern word spelt in an old
way. Old English OTOH is a completely different language and is about as
comprehensible as German for any modern english speaker.
David Brown <david.brown@hesbynett.no>: May 26 02:38PM +0200


> Sure, but like a lot of people you're missing the point. It doesn't matter
> if the data its trained on is out of date or just pure rubbish, its the fact
> that it somehow comprehends it and can make links between unrelated topics.
 
Again - I am not missing anything. I understand what you are saying,
and I am impressed with what it is able to do. But precisely because it
is trained on data that is out of date, wrong, or deliberate
misinformation as much as current and correct information, the
conclusions it reaches and links it makes are often worthless, or worse
than useless (because they contain critical errors, but are given with
such confidence and mixed with true statements).
 
> Plenty of very smart people in the past have argued about how many angels
> can fit on the head of a pin because of the nonsense in religious story books,
> that doesn't mean they're thick.
 
The fact that human knowledge and human intelligence do not always match
up does not have any bearing on how useful chatbot-style AI currently
is, or how dangerous it can be, or where its future might lie. Humans
can get things wrong too, intentionally or unintentionally - that does
not make the AI systems less wrong.
David Brown <david.brown@hesbynett.no>: May 26 03:30PM +0200

>> English (no mean feat in itself), then translating word for word where
>> the system could find a Middle English equivalent (with no regard for
 
> The fact that it can do it at all is amazing to me.
 
I fully agree.
 
 
> Chaucer can be understandable , often its a modern word spelt in an old
> way. Old English OTOH is a completely different language and is about as
> comprehensible as German for any modern english speaker.
 
Some Middle English is understandable, other parts are not - often the
context and culture differences are as much of a challenge as the words
themselves. But it is clear that Middle English is a precursor to
modern English, whereas Old English, or Anglo-Saxon, is very different.
Muttley@dastardlyhq.com: May 26 03:07PM

On Fri, 26 May 2023 15:30:58 +0200
>context and culture differences are as much of a challenge as the words
>themselves. But it is clear that Middle English is a precursor to
>modern English, whereas Old English, or Anglo-Saxon, is very different.
 
Anglo Saxon is to modern english what latin is to french, italian, spanish
etc. Obviously related and with shared words but not generally intelligable
to a modern romance language speaker.
David Dalton <dalton@nfld.com>: May 26 04:43AM -0230

cODINg :-)
 
--
https://www.nfld.com/~dalton/dtales.html Salmon on the Thorns (mystic page)
"This could be the final breath; This is life and death;
This is hard rock and water; Out here between wind and flame;
Between tears and elation; Lies a secret nation" (Ron Hynes)
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.

Thursday, May 25, 2023

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

Paavo Helde <eesnimi@osa.pri.ee>: May 26 12:11AM +0300

25.05.2023 22:18 R.Wieser kirjutas:
> Paavo,
 
>> For client sockets I do not use any BIO* functions.
 
> That still means you could be using either native or SSL_xxx sockets.
 
I'm using a native socket created by the C socket() call.
 
 
> That explains me not finding it, but also means that your offered code is of
> the same level as most of what I can find on the web : incomplete, leaving
> me guess to what else to get it to work is needed. :-\
 
Right. Nobody has said life should be easy ;-) Also, nobody has paid me
to prepare code examples which would exactly suit your needs.
 
 
> I might, in the future, try to find out how I can access Windows own cert
> store for it, but as said I want to keep the current code as simple/basic as
> possible.
 
You just snipped the code which you maybe will try to figure out in the
future.
 
> write something with /around that, but it would just be a "monkey see,
> monkey do" result - no real understanding of what I'm (effectivily) copying.
> :-(
 
Well, that's how it tends to be.
 
For openssl functions, you can at least just google "man FUNCTIONNAME"
to get the man page.
 
Of course, it does not help openssl contains hundreds of functions, half
of which are deprecated, and half of which are not needed for the task
at hand.
 
If one feels uncomfortable with raw sockets and raw openssl, one can use
some higher level interface like libcurl, or maybe Python. If I would
need to write this functionality again, I would probably use libcurl.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 25 02:07PM -0700

> With knowledge ande skill, thine endeavor shalodour.
> May this Middle English spelinge, inspirynge thyne queste,
> Illuminate C++'s misteries ande bringe thee the beste.
 
Thou art Dead. They took our jobs! Grrrr...
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.

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

"R.Wieser" <address@is.invalid>: May 25 09:39AM +0200

Hello all,
 
I've been trying whip up some code using (an older version of) OpenSSL.
I've ofcourse googled for information how to use it, but all I've been able
to find is some "examples" which stop directly after reading the reply (no
code to terminate the connection), or overly complex stuff aimed at a
certain target.
 
Currently I have got some code which shows :
 
1) a BIO_xxx way to retrieve unencrypted data
 
2) a mix between winsock and SSL_xxx to retrieve encrypted data - not sure
how/if the SSL part is closed
 
3) a mix between BIO_xxx and SSL_xxx to retrieve encrypted data, but which
doesn't include code to close the connection.
 
4) some other bits-and-pieces
 
The thing is, although I can mostly find the used commands back, I can't
find anything about how they interact. As such I have a hard time to even
find how to close an SSL connecion before I close the underlying BIO/socket
one. And for closing the BIO one I'm /assuming/ that all I need is
"BIO_free_all" ...
 
Also, 3) does stuff with BIO_xxx which caters to the SSL connection (like
setting the name of the target domain), while with 2) I only have to provide
the connected socket to SSL_set_fd to have everything work. IOW, I would
like to see some BIO_xxx code to connect (which it only seems to do on the
first BIO_read or BIO_write), and than have the SSL_xxx part take over the
connection the same way as with a standard socket.
 
One other thing : To keep my first steps as easy as possible I'm using
blocking sockets. Examples that jump into the deep end using async sockets
are of little value & use to me.
 
tl;dr:
I'm looking for some tutorial-style example code, explaining the basic
setup, request, retrieval and tear-down steps of an encrypted connection
using OpenSSL.
 
I'm currently using OpenSSL 0.9.8.0 , but that might just be because I've
not come across anything related to the current v3.1.0 version ...
 
Regards,
Rudy Wieser
Paavo Helde <eesnimi@osa.pri.ee>: May 25 03:26PM +0300

25.05.2023 10:39 R.Wieser kirjutas:
> using OpenSSL.
 
> I'm currently using OpenSSL 0.9.8.0 , but that might just be because I've
> not come across anything related to the current v3.1.0 version ...
 
OpenSSL 0.9 is seriously out of date. Currently supported stable
versions are 1.1.* and 3.0.*.
 
I do not have polished example code, my actual code is scattered around
several C++ classes and in partially platform-dependent source files.
Anyway, I can paste some snippets here, maybe these are helpful.
 
 
This code is using OpenSSL 3.0.8 for wrapping an existing connected
client-side cocked into SSL (Linux and Windows):
 
 
// Set short socket read timeout for SSL_connect, to avoid indefinite
hanging
::setsockopt(socketHandle, SOL_SOCKET, SO_RCVTIMEO, // ...
platform-dependent code ...
 
 
// Create new SSL connection state object
if ((ssl_ = SSL_new(context_->GetSSL_CTX())) == nullptr) {
// handle error
}
 
// Set up SNI (Server Name Indication), some websites like Google
complain if this is not done.
SSL_set_tlsext_host_name(ssl_, host.c_str());
 
// Attach the SSL session to the socket descriptor
SSL_set_fd(ssl_, static_cast<int>(socketHandle));

// When using the SSL_connect(3) or SSL_accept(3) routines, calling of
SSL_set_connect_state() or SSL_set_accept_state() is not needed.
 
int ret = SSL_connect(ssl_);
if (ret == 1) {
// OK, connected
}
 
// set the socket timeout larger if needed ...
 
********* write ******
 
int n = SSL_write(ssl_, buf, static_cast<int>(len));
if (n != static_cast<int>(len)) {
// handle error
 
******* read *****
 
ERR_clear_error();
int n = SSL_read(ssl_, buf, static_cast<int>(len));
if (n < 0) {
// handle errpr
int k = SSL_get_error(ssl_, n);
if (k == SSL_ERROR_WANT_READ) {
// timeout, or maybe the server side closed connection?
// the caller should reconnect and retry
} else {
// handle other error
}
}
 
 
********* cleanup ********
 
if (socketHandle != INVALID_SOCKET) {
closesocket(socketHandle);
}
if (ssl_) {
SSL_free(ssl_);
}
 
HTH
Paavo Helde <eesnimi@osa.pri.ee>: May 25 03:52PM +0300

25.05.2023 15:26 Paavo Helde kirjutas:
>> (no
>> code to terminate the connection), or overly complex stuff aimed at a
>> certain target.
 
BTW, ChatGPT4 seemed to be pretty strong with openssl, so you might just
ask it to generate some example programs. It even changed the code to
use proper std::unique_ptr lifetime management when I suggested that.
Muttley@dastardlyhq.com: May 25 03:15PM

On Thu, 25 May 2023 15:26:17 +0300
>25.05.2023 10:39 R.Wieser kirjutas:
>This code is using OpenSSL 3.0.8 for wrapping an existing connected
>client-side cocked into SSL (Linux and Windows):
 
I wouldn't use Windows socket code in Linux as windows sockets are severely
hobbled by not being able to be multiplexed on select() due to Microsofts
incomprehensible decision to make sockets a special handle type instead
of just a file descriptor meaning you can't mix them with other open file types
or inputs and they have to be converted into win messages or some such
overcomplicated crap in order to be received asynchronously unless you decide
to make life your even harder and spawn a new thread for each socket connection.
"R.Wieser" <address@is.invalid>: May 25 05:38PM +0200

Paavo,
 
> OpenSSL 0.9 is seriously out of date. Currently supported stable versions
> are 1.1.* and 3.0.*.
 
Yeah, I know. I already downloaded v3.1.0. But up until I can find example
and/or tutorial code about/for it its rather useless to me. And as I could
find info about that "seriously out of date" version that became the one I'm
working with.
 
> This code is using OpenSSL 3.0.8 for wrapping an existing connected
> client-side cocked into SSL (Linux and Windows):
 
That is quite similar to the 2) code I mentioned (using a pre-created and
connected native socket). I would like to keep everything in OpenSSL.
 
I would like to see a solution where I can create and connect a BIO socket
in a similar way I create a native socket (not providing hostname
information) and than use the BIO socket in the code you have posted.
 
The other solution I'm looking for is a full SSL_xxx one. No BIO_xxx or
native socket.
 
By the way: you use "context_->GetSSL_CTX()", but I do not see you cleanup
the returned handle.
 
It /might/ be done by something else, and that is exacly what I meant where
I say that I can find reference to commands, but not how they interact.
 
For "SSL_free" I found this :
https://www.openssl.org/docs/man1.0.2/man3/SSL_free.html Under "remarks" it
says
 
[quote]
SSL_free() also calls the free()ing procedures for indirectly affected
items, if applicable: the buffering BIO, the read and write BIOs, cipher
lists specially created for this ssl, the SSL_SESSION.
[/quote]
 
If it refers to the above "GetSSL_CTX" handle they have it pretty-well
hidden. :-(
 
Last remark : a quick search on four search-engines for that "GetSSL_CTX"
function turns up exactly nothing ...
 
Regards,
Rudy Wieser
"R.Wieser" <address@is.invalid>: May 25 05:51PM +0200

Muttley,
 
> I wouldn't use Windows socket code in Linux
 
:-) I would not want to use it the other way around either.
 
But thats a quite big "what if" step you're making there - what makes you
think that I would want to do that ?
 
I think I asked how I could do the whole thing just using (BIO_xxx and)
SSL_xxx functions. Besides the "I need example code of the whole thing,
from setting up upto cleaning up" ofcourse.
 
On the other hand, for my blocking handles implementation I probably need a
"select" somewhere, so my code doesn't stall waiting forever for a
reply/more data while the other side is doing the same.
 
Regards,
Rudy Wieser
Muttley@dastardlyhq.com: May 25 04:01PM

On Thu, 25 May 2023 17:51:06 +0200
 
>:-) I would not want to use it the other way around either.
 
>But thats a quite big "what if" step you're making there - what makes you
>think that I would want to do that ?
 
I don't care one way or the other, I was replying to Paavo, not you.
scott@slp53.sl.home (Scott Lurndal): May 25 04:13PM

>and/or tutorial code about/for it its rather useless to me. And as I could
>find info about that "seriously out of date" version that became the one I'm
>working with.
 
Have you a copy of the O'reilly openssl book?
 
There's a copy on github.
Paavo Helde <eesnimi@osa.pri.ee>: May 25 07:43PM +0300

> or inputs and they have to be converted into win messages or some such
> overcomplicated crap in order to be received asynchronously unless you decide
> to make life your even harder and spawn a new thread for each socket connection.
 
I agree life would be easier if I would only need to support UNIX
everything-is-a-file concepts. Alas, that's not the case for me.
 
BTW, the replacement of select() in Windows is WaitForMultipleObjects().
Windows messages are not needed (which is good because usually I have no
window which could receive them).
 
Anyway, sockets low-level programming is not a recommended approach.
Suggesting libcurl or Boost ASIO instead, which take care of some
aspects. OTOH, if things go south (read: corporate networks with
prescribed security regulations) it might be harder to get multiple
layers of software working, instead of a single layer.
Paavo Helde <eesnimi@osa.pri.ee>: May 25 08:12PM +0300

25.05.2023 18:38 R.Wieser kirjutas:
> information) and than use the BIO socket in the code you have posted.
 
> The other solution I'm looking for is a full SSL_xxx one. No BIO_xxx or
> native socket.
 
For client sockets I do not use any BIO* functions.
 
 
> By the way: you use "context_->GetSSL_CTX()", but I do not see you cleanup
> the returned handle.
 
Right. The GetSSL_CTX() is my own function which returns a pointer to
shared SSL_CTX structure. This SSL_CTX is created once, is shared by all
SSL client connections and will be released only at the end of the program.
 
Setting up this context involves loading the trusted CA certificates
from various locations, and setting up a verify callback which logs
errors or warning, but also verifies the certificate against the Windows
system cert store, on Windows.
 
I can list the functions I use for setting up and releasing this
SSL_CTX, in call order (error checks omitted for brevity):
 
SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
 
const SSL_METHOD* method = TLS_client_method();
SSL_CTX* context = SSL_CTX_new(method);
SSL_CTX_set_default_verify_paths(context);
 
// These can be called 0 or more times
SSL_CTX_load_verify_file(context, trustedCaBundleFile.c_str());
SSL_CTX_load_verify_dir(context, trustedCaCertDir.c_str())
 
SSL_CTX_set_verify(context, SSL_VERIFY_PEER, MySSLVerifyCallback);
 
 
***** cleanup *********
 
SSL_CTX_free(context);
 
******** callback *************
 
NOTE: contains my own functions, you need to adapt creatively
 
int MySSLVerifyCallback(int preverify_ok, X509_STORE_CTX *x509_ctx) {
try {
if (preverify_ok) {
// openssl has verified the cert, OK.
return 1; // success
}
 
X509* err_cert = (x509_ctx?
X509_STORE_CTX_get_current_cert(x509_ctx): nullptr);
const char* errMessage;
int err;
if (x509_ctx) {
err = X509_STORE_CTX_get_error(x509_ctx);
errMessage = X509_verify_cert_error_string(err);
} else {
err = -1;
errMessage = "x509_ctx==nullptr";
}
 
// Verify the cert against the global Windows certificates store
(ACINF-3817).
if (VerifyTLS(err_cert)) {
return 1; // success
}
 
char buf[256] = { 0 };
if (err_cert) {
X509_NAME_oneline(X509_get_subject_name(err_cert), buf, sizeof(buf)
- 1);
}
std::string msg = Sprintf("SSL cert verify error: num=%d: %s:
%s")(err)(errMessage)(buf);
// handle as an error or as a warning
return 1; // success
return 0; // failure
} catch (...) {
// handle error
return 0; // failure
}
}
 
 
********** VerifyTLS() for Windows **************
NOTE: contains my own functions, you need to adapt creatively
 
// Need a separate function because OPENSSL_free is a macro.
void FreeOpenSslBuffer(unsigned char* buffer) {
OPENSSL_free(buffer);
}
 
bool VerifyTLS(X509* cert) {
// openssl failed to verify the cert.
 
// Try to verify the cert against Windows cert store
unsigned char* buffer = nullptr;
int len = i2d_X509(cert, &buffer);
if (len < 0) {
throw Exception(ERR_IO, "i2d_X509() failed");
}
ASSERT(buffer);
DEBUG_ASSERT(len > 0);
ON_BLOCK_EXIT(FreeOpenSslBuffer, buffer);
 
CERT_CHAIN_PARA thing;
::memset(&thing, 0, sizeof(thing));
thing.cbSize = sizeof(thing);
PCCERT_CONTEXT winContext =
::CertCreateCertificateContext(X509_ASN_ENCODING, buffer, len);
if (!winContext) {
syserr_t errorCode = GetLastErrorCode();
throw Exception(ERR_IO, "CertCreateCertificateContext() failed: " +
GetSysErrorString(errorCode));
}
ON_BLOCK_EXIT(::CertFreeCertificateContext, winContext);
 
PCCERT_CHAIN_CONTEXT chain = nullptr;
if (::CertGetCertificateChain(
nullptr,
winContext,
nullptr,
nullptr,
&thing,
CERT_CHAIN_CACHE_END_CERT|CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY,
nullptr,
&chain))
{
ON_BLOCK_EXIT(::CertFreeCertificateChain, chain);
DWORD errorStatus = chain->TrustStatus.dwErrorStatus;
 
if (errorStatus == 0) {
return true; // Windows approved the cert
}
}
return false;
}
"R.Wieser" <address@is.invalid>: May 25 09:18PM +0200

Paavo,
 
> For client sockets I do not use any BIO* functions.
 
That still means you could be using either native or SSL_xxx sockets.
 
>> By the way: you use "context_->GetSSL_CTX()", but I do not see you
>> cleanup the returned handle.
 
> Right. The GetSSL_CTX() is my own function
 
That explains me not finding it, but also means that your offered code is of
the same level as most of what I can find on the web : incomplete, leaving
me guess to what else to get it to work is needed. :-\
 
> Setting up this context involves loading the trusted CA certificates from
> various locations,
 
Done,
 
> and setting up a verify callback which logs errors or warning,
 
The example I found uses "SSL_get_verify_result" .
 
Which makes me remember that I still need to find a demo domain which
purposely has a wrong cerificate - to test if the code I have actually
works.
 
> but also verifies the certificate against the Windows system cert store,
> on Windows.
PEM
Currently I'm using SSL_CTX_load_verify_locations, using a local file.
 
I might, in the future, try to find out how I can access Windows own cert
store for it, but as said I want to keep the current code as simple/basic as
possible.
 
> I can list the functions I use for setting up and releasing this SSL_CTX,
> in call order (error checks omitted for brevity):
 
I see a *lot* more code than I'm currently using myself. I can likely
write something with /around that, but it would just be a "monkey see,
monkey do" result - no real understanding of what I'm (effectivily) copying.
:-(
 
 
 
By the way, the below is what I started with. First a basic non-ssl
retrieval of a webpage, afterwards the same retrieval but now over SSL.
 
http://jokinkuang.github.io/2015/02/27/how_to_do_http_&_https_request_with_openssl.html
 
As you can see it does most everything with BIO_xxx calls, with just a
sliver of SSL_xxx related calls thrown in.
 
This one
 
https://gist.githubusercontent.com/endSly/8369715/raw/ee86f381e814499bdffd34267b5e371b21839ecb/sslconnect.c
 
uses a native socket, connects it and than gives it to the SSL_xxx layer.
There is no "BIO_set_conn_hostname" (or an SSL_xxx version of it!) in sight
anywhere, but it seems to work nonwithstanding (probably extracting the
domain name and port from the native socket)
 
I've got a number of other snippets, but as I said, most are incomplete or
(far) beyond a basic setup. Like this one (which has thrown a number of
snippets on a single page):
 
https://cpp.hotexamples.com/examples/-/-/SSL_connect/cpp-ssl_connect-function-examples.html
 
Regards,
Rudy Wieser
Keith Thompson <Keith.S.Thompson+u@gmail.com>: May 25 02:05PM -0700

>>working with.
 
> Have you a copy of the O'reilly openssl book?
 
> There's a copy on github.
 
Do you mean "Network Security with OpenSSL" by John Viega, Matt Messier,
and Pravir Chandra? The last update was June 2002, when the latest
release was 0.9.7d.
 
I found a PDF copy of the book on GitHub. It appears to be pirated.
 
O'Reilly sometimes releases some books for free, but they haven't done
so with this one.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: May 24 09:47PM -0400

> With knowledge ande skill, thine endeavor shalodour.
> May this Middle English spelinge, inspirynge thyne queste,
> Illuminate C++'s misteries ande bringe thee the beste.
 
WOW. Just WOW. The back-handed compliment in the last verse is my
favorite. Thanks!
Muttley@dastardlyhq.com: May 25 09:04AM

On Wed, 24 May 2023 21:47:19 -0400
>> Illuminate C++'s misteries ande bringe thee the beste.
 
>WOW. Just WOW. The back-handed compliment in the last verse is my
>favorite. Thanks!
 
Personally I find its abilities rather concerning since they're only
going to improve exponentially.
Michael S <already5chosen@yahoo.com>: May 25 06:48AM -0700

> >favorite. Thanks!
> Personally I find its abilities rather concerning since they're only
> going to improve exponentially.
 
Does it really resembles Middle English or just an arbitrary funny misspelling?
David Brown <david.brown@hesbynett.no>: May 25 04:17PM +0200

>> favorite. Thanks!
 
> Personally I find its abilities rather concerning since they're only
> going to improve exponentially.
 
It will improve in some ways, and not in others. It can always get
faster and more flexible (though not "exponentially" so). But current
AI bots suffer from several critical flaws, and it is not easy to see
how they can be fixed. They base their knowledge on what they find
online, but have no way to judge the veracity of the sources, they have
no concept of error margins and reliability of the information they have
processed or produce, no understanding of ethics or appropriateness
(beyond a few simple pattern-matching rules rushed in to cut down on the
worst abuses).
 
This all means it has no idea when it is telling the truth, and when it
is lying or simply making things up. When making this poem, it has no
idea if the sources it used for the language were real Middle English,
modernised spelling of Middle English, made up pretend Middle English,
sources from 1066, sources from 1500, or whatever. It doesn't really
matter for a fun sample like this - it looks very impressive, though it
would make even the most amateur Chaucer fan cringe. But until there
are major fundamental changes, the use of such AI tools is severely
limited because they can't be trusted to have any basis in truth or reality.
 
Still, they can cheat in exams, write speeches for politicians and work
as journalists for the Daily Mail and Fox news, and no one will notice.
Muttley@dastardlyhq.com: May 25 03:24PM

On Thu, 25 May 2023 06:48:34 -0700 (PDT)
>> going to improve exponentially.
 
>Does it really resembles Middle English or just an arbitrary funny misspell=
>ing?
 
Better than I could do and I like to think it couldn't just conjure up these
sorts of spellings but did learn them somewhere.
Muttley@dastardlyhq.com: May 25 03:27PM

On Thu, 25 May 2023 16:17:30 +0200
>AI bots suffer from several critical flaws, and it is not easy to see
>how they can be fixed. They base their knowledge on what they find
>online, but have no way to judge the veracity of the sources, they have
 
Neither do humans frankly.
 
>processed or produce, no understanding of ethics or appropriateness
>(beyond a few simple pattern-matching rules rushed in to cut down on the
>worst abuses).
 
Neither do some humans. It doesn't mean they can't think. You're missing
the elephant in the room - this thing might not be concious but it is
thinking , its not a dumb stats based system like a markov model or similar.
 
>Still, they can cheat in exams, write speeches for politicians and work
>as journalists for the Daily Mail and Fox news, and no one will notice.
 
Only after they've worked their way up from writing for woke comics such as
The Guardian.
David Brown <david.brown@hesbynett.no>: May 25 08:49PM +0200

>> how they can be fixed. They base their knowledge on what they find
>> online, but have no way to judge the veracity of the sources, they have
 
> Neither do humans frankly.
 
True - but at least some of us can do a lot better job. No one is
immune to being fooled, and some people get fooled a /lot/, but these AI
systems have not yet reached the level of even the daftest flat-earthers
and "Q anon" followers.
 
 
> Neither do some humans. It doesn't mean they can't think. You're missing
> the elephant in the room - this thing might not be concious but it is
> thinking , its not a dumb stats based system like a markov model or similar.
 
I understand that, and I'm not missing anything.
 
The key, I think, is that humans go through many years of learning and
upbringing - these systems are like a child that has read thousands of
books, but has never been taught about trustworthy sources, never seen
anything bad happen, never made mistakes and been corrected. They are
highly knowledgeable and totally naïve. They need patient teachers and
"parents", working with them for many years at least, and no one is
willing to wait for that.
 
David Brown <david.brown@hesbynett.no>: May 25 08:58PM +0200

On 25/05/2023 15:48, Michael S wrote:
>> Personally I find its abilities rather concerning since they're only
>> going to improve exponentially.
 
> Does it really resembles Middle English or just an arbitrary funny misspelling?
 
It vaguely resembles Middle English - at least some of the funny
spellings are reasonable versions (transliterated into modern letters).
But it appears to have been done by making up a poem about C++ in modern
English (no mean feat in itself), then translating word for word where
the system could find a Middle English equivalent (with no regard for
context or consistency of time and place - Middle English spanned 400
years and was significantly different in different parts of the British
Isles). Some modern words have been modified by patterns common at the
time in an attempt at following Middle English grammar, others have not.
 
As a test of how authentic it is, I guess that most people in this group
can understand most of the poem. But if you look up some Chaucer or
other real Middle English poetry, I doubt you'll have much idea at all
about what it is saying - at least not without a lot of effort.
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: May 24 09:13PM -0400

Öö Tiib wrote:
> how many destructors to call with delete[] to pointer allocated with
> new[] is not exposed to programmers for to write such a class
> themselves if the standard library does not bother.
 
Actually, I meant someone slightly different. The shame is that the
vector class is not factored onto an exact-size array (let's call it
"block") and the rest of vector functionality.
 
vector has the design flaw that it is too many things: it is the owner
of several contiguous objects in memory but also the growth strategy.
 
The block is useful independently of vector if:
 
a) a custom growth strategy is needed; or
b) no growth is needed at all (a very often case in my practice).
 
For small vectors, replacing them with blocks could provide significant
space savings (not limited by only capacity even when compiler trickery
is not used; e.g. block<size_t> could be specialized so that the
underlying storage layout is implemented like this:
 
struct { const size_t N; size_t data[]; }; // or like this
struct { const size_t *end; size_t data[]; };
 
This way, 2 words of memory are saved (capacity and begin pointer) and
one indirection is also saved when one needs to access elements in a
block passed by reference or pointer so this brings both performance and
space savings.
 
Then, as I said, for the purpose of implementing the block (again, maybe
of only some specializations), using compiler trickery for computing N
*could* be justified. *could* is a keyword here. It *could* also be
useless or even detrimental performance-wise. It is feasible that the
 
operator new[]
 
would actually take more memory from the OS for N elements than
(non-array) allocation function
 
void* operator new(size[, align_val_t]...)
 
would for the same N elements. In this case, no gain is achieved from
using operator new[] and compiler trickery over using the single-object
form of allocation function "operator new" and system-independent
implementation.
 
-Pavel
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: May 24 09:16PM -0400

>> shared_ptr. I think the C++ designers thought this isn't necessary.
 
> Well they thought it necessary to be able to store arrays and index them
> inside a shared pointer, so why didn't they complete the job?
 
The support of indexing can be considered to be the support of the
existing functionality of a raw pointer as it also supports indexing,
but not iteration.
 
-Pavel
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: May 24 09:40PM -0400

Alf P. Steinbach wrote:
>> shared_ptr instatiation *type*
 
> It is.
 
> For example, otherwise my example of how to do this would not work.
Yes, but notice that for Mutley, it seemed more natural that N was the
the run-time size of the array (somewhere up this thread he used the
argument that the compiler is able to get N to destroy every of N
allocated objects when delete[] is called -- on raw pointer -- that does
not have compile-time N). This tells me that different people would feel
differently about which N is "natural" (compile-time or runtime) so
standardizing this would be counter-intuitive either way.
 
 
>> shared_ptr<mystruct[3]> sp(new mystruct[getNOfMyStructs()]);
 
>> What can possibly go wrong? (TM)
 
> You shot your leg off.
I certainly did. This is exactly why I do not mind if this particular
way to self-inflict harm on myself is not supported :-). smart pointers
were supposed to be safer than the raw ones, after all, and even raw
pointers do not support iteration.
 
 
> C++ allows that, in general.
Yes, that was one of the design goals. Blow up your whole leg.. Going on
tangent, I am still mad at them they broke this performance-over-safety
promise when they decided that most-derived-class's virtual function
cannot be called from a constructor or destructor of a base class.
"What's safe enough for Java should be safe enough for C++" says I :-).
 
 
> shared_ptr provides support for arrays,
I disagree. I think what you mean by "support for array" (indexing?) is
actually the support for the raw pointers to memory allocated by
operator new[]. The argument that we pass to the shared_ptr constructor in
 
shared_ptr<mystruct[3]> sp(new mystruct[3]);
 
(and that the shared_ptr likely stores underneath) is such a raw
pointer, not an array.
 
> including I believe restrictions
> on conversions, but not total type safety enforcement.
 
> - Alf
 
-Pavel
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: May 24 09:20PM -0700

On 5/24/2023 6:40 PM, Pavel wrote:
>>>>>> shared pointers?
>>>>> These shared pointers do not store arrays. They store pointers to
>>>>> memory object allocated with operator new[].
[...]
 
> shared_ptr<mystruct[3]> sp(new mystruct[3]);
 
> (and that the shared_ptr likely stores underneath) is such a raw
> pointer, not an array.
[...]
 
Almost has to be.
Muttley@dastardlyhq.com: May 25 08:51AM

On Wed, 24 May 2023 09:48:05 -0700 (PDT)
>Target: x86_64-pc-linux-gnu
>Thread model: posix
>InstalledDir: /usr/bin
 
Beats me. I'm using clang on a Mac and I tried it again in case I'd not
cut and pasted properly but it still failed.
 
However this wouldn't be the first time the Apple version of Clang differs
from versions on other platforms.
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.

Wednesday, May 24, 2023

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

"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu>: May 23 09:39PM -0700

> return 0;
> }
 
> I've tried other combinations too, nothing works.
 
Would this be an acceptable alternative? It compiles and executes as I expected it to:
 
#include <iostream>
#include <memory>
 
using namespace std;
 
struct mystruct
{
mystruct() { cout << "Con " << this << endl; };
~mystruct() { cout << "Dest " << this << endl; }
void func() { cout << "Func " << this << endl; }
};
 
 
int main()
{
shared_ptr<mystruct[1][3]> sp(new mystruct[1][3]);
sp[0][0].func();
sp[0][1].func();
sp[0][2].func();
for(auto &ms: sp.get()[0]) ms.func(); // <--- Doesn't compile
return 0;
}
Muttley@dastardlyhq.com: May 24 08:50AM

On Tue, 23 May 2023 21:39:46 -0700 (PDT)
>> I've tried other combinations too, nothing works.
 
>Would this be an acceptable alternative? It compiles and executes as I expe=
>cted it to:
 
Clang doesn't like it I'm afraid:
 
fenris$ c++ -std=c++17 t.cc
t.cc:16:32: error: no matching constructor for initialization of 'shared_ptr<mys
truct[1][3]>'
shared_ptr<mystruct[1][3]> sp(new mystruct[1][3]);
Bonita Montero <Bonita.Montero@gmail.com>: May 24 02:58PM +0200

> t.cc:16:32: error: no matching constructor for initialization of 'shared_ptr<mys
> truct[1][3]>'
> shared_ptr<mystruct[1][3]> sp(new mystruct[1][3]);
 
It compiled for me with clang++ 14.
"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu>: May 24 09:48AM -0700

> t.cc:16:32: error: no matching constructor for initialization of 'shared_ptr<mys
> truct[1][3]>'
> shared_ptr<mystruct[1][3]> sp(new mystruct[1][3]);
 
On my machine, it works:
 
clang++-14 -std=c++17 shared_pointer.cpp -o shared_pointer
 
clang++-14 --version
Ubuntu clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Muttley@dastardlyhq.com: May 24 04:25PM

A bit off topic but thought this might be appreciated. I asked chatGPT to
describe C++ as middle english poem. This AI is incredible:
 
In the realme of programmynge, C++ doth resideth,
A langage of myghte, its secrets it provideth.
With intrikat syntax, lik a maze profounde,
It chaunges the wey ofe programeers, yf yow wolde.
 
Objects, lik knyghtes, withinne classes doth resyde,
Encapsulatynge data ande methodes, they abyde.
Classes, lik castels, bestowe noble myghte,
Inheritance passeth lineage, shynynge bryghte.
 
Polymorphisme, a marvelouse art to use,
Transfigureth objects, takynge dyvers forme and hues.
Functiones, lik minstrels, her songes they do synge,
With parametres ande returnes, her melodyes sprynge.
 
Yet, taketh heed, noble programmer, for trappes may appeere,
Memory lekes ande faultes, yf yow art yclept afeared.
Pointers ande referencys, thy guides in this affray,
Shal guide thee to memory managynge in the righte way.
 
So, embarketh on this journe, thou valyaunt coder,
With knowledge ande skill, thine endeavor shalodour.
May this Middle English spelinge, inspirynge thyne queste,
Illuminate C++'s misteries ande bringe thee the beste.
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.

Tuesday, May 23, 2023

Digest for comp.lang.c++@googlegroups.com - 12 updates in 2 topics

Vir Campestris <vir.campestris@invalid.invalid>: May 23 11:33AM +0100

On 17/05/2023 16:44, Bonita Montero wrote:
> Am 17.05.2023 um 17:37 schrieb Scott Lurndal:
 
>> And you know this, how, exactly?
> I/O on mainframes is also PCI-whatever today.
 
Back when I worked on mainframes, which might be before you were born,
some of the big systems had multiple memory units each of which could be
connected to disc and/or tape drives.
 
They were of course all connected to the CPU cluster.
 
Going to a PCI based system would tend to indicate that there is a
single bus taking all the I/O and CPU traffic, which would be a bottleneck.
 
If the mainframes of 40 years ago had got around that bottleneck why
would it have been introduced in the time since?
 
I suspect others here have more recent knowledge than I do.
 
Andy
Richard Damon <Richard@Damon-Family.org>: May 23 07:49AM -0400

On 5/23/23 6:33 AM, Vir Campestris wrote:
> would it have been introduced in the time since?
 
> I suspect others here have more recent knowledge than I do.
 
> Andy
 
 
I think part of the answer was that mainframes were much more of a
"Distributed" system then more modern machines. The "I/O Channels" were
very much a form of processor assigned to do certain pieces of the work.
 
The logic was slower, so the wires between the modules wasn't as
critical, so you could have fatter connections.
scott@slp53.sl.home (Scott Lurndal): May 23 02:51PM


>They were of course all connected to the CPU cluster.
 
>Going to a PCI based system would tend to indicate that there is a
>single bus taking all the I/O and CPU traffic, which would be a bottleneck.
 
 
In the mainframes, there was still a single bus from the memory
subsystem to the I/O subystem. And in those days, 8MByte/second
was a high-speed transfer rate from memory to the I/O controller,
and 1Mbyte/sec was the typical transfer rate between a disk
drive and the disk controller, allowing eight controllers to
simultaneously transfer data to/from memory (interleaved with
processor accesses to the same memory).
 
The PCI bus designed in the late 80s/early 90s was indeed a bus,
(originally at 33mhz, 66mhz for PCI-X).
 
Modern PCI express is _not_ a bus. It's a point-to-point serial link
between the host memory complex and an I/O controller (storage
host adapter, network interface card, etc).
 
PCI Express Generation 6 will transfer 128 Gigabytes/second
in a 16-lane configuration, and most high-end processors support
multiple PCIe 6.0 controllers.
 
 
>I suspect others here have more recent knowledge than I do.
 
See above.
Muttley@dastardlyhq.com: May 23 02:54PM

On Tue, 23 May 2023 14:51:25 GMT
>Modern PCI express is _not_ a bus. It's a point-to-point serial link
 
Though these days "serial" means little more than a single data line. Modern
serial comms such as USB and SATA are packet based and have more in common with
ethernet than RS232.
Bonita Montero <Bonita.Montero@gmail.com>: May 23 06:26PM +0200

Am 23.05.2023 um 12:33 schrieb Vir Campestris:
 
> If the mainframes of 40 years ago had got around that bottleneck
> why would it have been introduced in the time since?
 
Whatever PCIe I/O-devices mainframes have today - I get about ~1.1E6
/ ~4GB/s random 4kB-I/Os per second on my 90$ Samsung 980 Pro 1TB PCIe
4.0 SSD with 3 - 4% CPU load (AMD 7950X, I/O completion ports - Perfor-
mance Monitor shows ~1.1e6 interrupts per second) under Windows 11 and
I guess that today's mainframes do that not much more efficient.
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: May 22 11:20PM -0400


> N might be lost to the user but the compiler/runtime is quite well aware of
> what it is otherwise delete[] couldn't work which makes me wonder why its
> not made available to range based loops.
 
Well, there are (up to) 2 different Ns. First N is a bound of template
parameter when it is an array with a known bound. Second N is that
number of elements that compiler knows (in the implementation-dependent
way) when array delete expression destroys the objects.
 
If begin() and end() on shared_ptr were defined, would these lines
remain legal C++ code?
 
shared_ptr<mystruct[3]> spt1(new mystruct[2]); // (a)
 
 
shared_ptr<mystruct[2]> spt2(new mystrucct[3]); // (b)
 
 
shared_ptr<mystruct[2]> spt3(getNFromFile()); // (c)
 
?
 
If yes, how many elements would range loop iterate thru?
 
I think maybe if the Standard only allowed shared_ptr specialization
with an array of unknown bound, the behavior of end() would be
technically easier to define (but still difficult to implement as any
implementation-specific feature).
 
Still, this would take us beyond smart pointer design goal -- which is
in essence to improve on safety of a raw pointer while preserving as
many of the raw pointer capabilities as possible. If we need an array,
we have std::array; if we have a vector, we have std::vector and
std::valarray.
 
(I personally think it is a shame that we don't have an exact-size
vector (i.e. a vector sized like valarray, with no capacities) but still
it is not a good excuse to abuse poor little smart pointers. For the
exact-size vector, using new[]- allocated memory and compiler trickery
for N could be justified).
 
-Pavel
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: May 23 07:11AM +0200

On 2023-05-21 5:53 AM, Pavel wrote:
> unclear benefit.
 
> E.g. assume that, in line with your example, N becomes part of
> shared_ptr instatiation *type*
 
It is.
 
For example, otherwise my example of how to do this would not work.
 
 
 
> or, even better:
 
> shared_ptr<mystruct[3]> sp(new mystruct[getNOfMyStructs()]);
 
> What can possibly go wrong? (TM)
 
You shot your leg off.
 
C++ allows that, in general.
 
shared_ptr provides support for arrays, including I believe restrictions
on conversions, but not total type safety enforcement.
 
 
- Alf
"Öö Tiib" <ootiib@hot.ee>: May 23 12:14AM -0700

On Tuesday, 23 May 2023 at 06:22:18 UTC+3, Pavel wrote:
> it is not a good excuse to abuse poor little smart pointers. For the
> exact-size vector, using new[]- allocated memory and compiler trickery
> for N could be justified).
 
IOW it is shame that the implementation-dependent way of figuring
how many destructors to call with delete[] to pointer allocated with
new[] is not exposed to programmers for to write such a class
themselves if the standard library does not bother.
Muttley@dastardlyhq.com: May 23 08:17AM

On Mon, 22 May 2023 18:10:54 +0200
 
>No, if the shared_ptr should behave like a container you'd need
>an iterator-type with * and ++ and a begin and end-method on the
>shared_ptr. I think the C++ designers thought this isn't necessary.
 
Well they thought it necessary to be able to store arrays and index them
inside a shared pointer, so why didn't they complete the job?
Bonita Montero <Bonita.Montero@gmail.com>: May 23 10:20AM +0200


> Well they thought it necessary to be able to store arrays and index
> them inside a shared pointer, so why didn't they complete the job?
 
No need to worry about that because there is a workaround that has
other benefits as well.
Muttley@dastardlyhq.com: May 23 08:24AM

On Tue, 23 May 2023 10:20:08 +0200
>> them inside a shared pointer, so why didn't they complete the job?
 
>No need to worry about that because there is a workaround that has
>other benefits as well.
 
Yes I know, but thats not the point. If they going to add features to the
language why don't they do it properly instead of some half assed job?
Bonita Montero <Bonita.Montero@gmail.com>: May 23 03:44PM +0200


> Yes I know, but thats not the point. If they going to add features to the
> language why don't they do it properly instead of some half assed job?
 
For me the current solution is proper enough.
C-style arrays aren't very common in C++.
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.