comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@notmyhomepage.invalid>
Subject: Re: Introductory Presentations, especially aimed at C++ programmers!
Date: Fri, 9 Dec 2016 09:35:21 +0100
Date: 2016-12-09T09:35:21+01:00	[thread overview]
Message-ID: <o2dq9o$37c$1@dont-email.me> (raw)
In-Reply-To: <87mvg551pi.fsf@nightsong.com>

On 09.12.16 02:30, Paul Rubin wrote:
> I would say that C++ is stronger in this area than Ada, since it has
> dynamically sized strings in the STL container library.  You'd use those
> instead of fixed-size buffers, so there's no way to overflow except OOM.

But can you pass std::string to the functions of Win32?

(I'm curious about the specifics in this example, since, e.g.,
RegQueryValueEx has a usage protocol associated with it and
seems to not produce an overflow of the BYTE far* buffer.)

Also, I think that the STL still requires discipline when
one uses indexing. This little playground can produce a number
of results that only prompt a cliché:
"any competent programmer will avoid any of these mistakes"...


void reorder(std::string& s) {
     using str = std::string;

     const str::const_iterator right_end = s.end();
     const str::const_reverse_iterator left_end = s.rend();
     str::iterator lr;
     str::reverse_iterator rl;

     for (lr = s.begin(), rl = s.rbegin() - 1;
	 lr != right_end && rl != left_end;
	 lr += 2, rl += 2)  // or try `rl -= 2`
     {
	*(lr + 2) = *lr;
	*(rl + 2) = *rl;	// and `rl - 2`
     }
}

Segfaults, null characters, and some harder to test
algorithmic errors, depending on variation.

-- 
"HOTDOGS ARE NOT BOOKMARKS"
Springfield Elementary teaching staff


  parent reply	other threads:[~2016-12-09  8:35 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 12:24 Introductory Presentations, especially aimed at C++ programmers! John McCabe
2009-07-10 21:49 ` jimmaureenrogers
2009-07-10 23:37   ` wwilson
2009-07-11  0:07     ` jimmaureenrogers
2009-07-12  4:00       ` wwilson
2009-07-11  8:15 ` Stephen Leake
2009-07-15  6:43 ` Jean-Pierre Rosen
2016-12-07 17:06 ` john
2016-12-07 17:44   ` Luke A. Guest
2016-12-07 18:35     ` Jeffrey R. Carter
2016-12-07 23:03       ` Randy Brukardt
2016-12-07 23:47         ` Jeffrey R. Carter
2016-12-08  0:08           ` Paul Rubin
2016-12-09 22:01             ` Randy Brukardt
2016-12-09 22:18               ` Jeffrey R. Carter
2016-12-13  0:53                 ` Randy Brukardt
2016-12-13  3:21                   ` Jeffrey R. Carter
2016-12-13 21:15                     ` Robert A Duff
2016-12-13 22:05                       ` Jeffrey R. Carter
2016-12-13 22:52                         ` Robert A Duff
2016-12-14  0:02                           ` Jeffrey R. Carter
2016-12-13 23:05                         ` Randy Brukardt
2016-12-14  0:13                           ` Jeffrey R. Carter
2016-12-14 22:48                             ` Randy Brukardt
2016-12-15  0:00                               ` Jeffrey R. Carter
2016-12-15 10:46                                 ` Maciej Sobczak
2016-12-16  7:37                                   ` Paul Rubin
2016-12-15 20:14                                 ` Niklas Holsti
2016-12-15 20:27                                   ` Jeffrey R. Carter
2016-12-15 21:04                                     ` Niklas Holsti
2016-12-15 21:40                                       ` Jeffrey R. Carter
2016-12-16  7:41                                     ` Paul Rubin
2016-12-13 22:50                     ` Randy Brukardt
2016-12-14  0:08                       ` Jeffrey R. Carter
2016-12-14  1:01                         ` Shark8
2016-12-08  8:08           ` Maciej Sobczak
2016-12-08  8:38             ` Dmitry A. Kazakov
2016-12-08 10:25             ` Paul Rubin
2016-12-08 13:39               ` Maciej Sobczak
2016-12-09  1:30                 ` Paul Rubin
2016-12-09  8:31                   ` J-P. Rosen
2016-12-09  8:58                     ` Paul Rubin
2016-12-09  9:18                       ` J-P. Rosen
2016-12-09  9:27                         ` Paul Rubin
2016-12-09 10:49                           ` J-P. Rosen
2016-12-09 19:58                             ` Jeffrey R. Carter
2016-12-09  8:35                   ` G.B. [this message]
2016-12-09  8:57                     ` Paul Rubin
2016-12-09 22:15                     ` Randy Brukardt
2016-12-09 21:58           ` Randy Brukardt
2016-12-08  8:23     ` Maciej Sobczak
2016-12-08 18:54   ` Adam Jensen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox