Monday, January 22, 2018

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

arnuld <sunrise@invalid.address>: Jan 22 01:24PM

AIM: to print elements of a multidimensional array.
PROBLEM: it prints addresses
 
I known from C.7.2 of Stroustrup 3/e that there are no multidimensional
arrays on hardware level. These dimensions exist in compiler-source only.
Question is a[i] generally prints the value at \i\. Then why not here ?
 
 
#include <iostream>
#include <string>
 
using std::cout;
 
int main()
{
int arr[4][4];
 
for(int i = 0; i != 4; ++i)
{
for(int j = 0; j != 4; ++j)
{
arr[i][j] = i+j;
cout << "arr[" << i << "][" << j << "] = arr[" << arr[i] << "["
<< arr[j] << "]\n";
//cout << arr[i][j] << " ";
}
}
 

 
return 0;
}
=========== OUTPUT =================
[arnuld@arch64 programs]$ g++ -std=c++17 -pedantic -Wall -Wextra
arrays.cpp
[arnuld@arch64 programs]$ ./a.out
arr[0][0] = arr[0x7ffda9f1e9e0[0x7ffda9f1e9e0]
arr[0][1] = arr[0x7ffda9f1e9e0[0x7ffda9f1e9f0]
arr[0][2] = arr[0x7ffda9f1e9e0[0x7ffda9f1ea00]
arr[0][3] = arr[0x7ffda9f1e9e0[0x7ffda9f1ea10]
arr[1][0] = arr[0x7ffda9f1e9f0[0x7ffda9f1e9e0]
arr[1][1] = arr[0x7ffda9f1e9f0[0x7ffda9f1e9f0]
arr[1][2] = arr[0x7ffda9f1e9f0[0x7ffda9f1ea00]
arr[1][3] = arr[0x7ffda9f1e9f0[0x7ffda9f1ea10]
arr[2][0] = arr[0x7ffda9f1ea00[0x7ffda9f1e9e0]
arr[2][1] = arr[0x7ffda9f1ea00[0x7ffda9f1e9f0]
arr[2][2] = arr[0x7ffda9f1ea00[0x7ffda9f1ea00]
arr[2][3] = arr[0x7ffda9f1ea00[0x7ffda9f1ea10]
arr[3][0] = arr[0x7ffda9f1ea10[0x7ffda9f1e9e0]
arr[3][1] = arr[0x7ffda9f1ea10[0x7ffda9f1e9f0]
arr[3][2] = arr[0x7ffda9f1ea10[0x7ffda9f1ea00]
arr[3][3] = arr[0x7ffda9f1ea10[0x7ffda9f1ea10]
[arnuld@arch64 programs]$
 
 
 
 
--
-- arnuld
http://lispmachine.wordpress.com/
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 22 02:34AM -0800

On Sunday, January 21, 2018 at 12:12:46 PM UTC-5, Rick C. Hodgin wrote:
> schools. These people are mistaken — The Church of FSM is legit, and
> backed by hard science. Anything that comes across as humor or satire is
> purely coincidental. #atheism
 
#1 -- I, the real Rick C. Hodgin, did not write this post I'm replying
to.
 
#2 There are three religions:
 
1) True, faithful, Biblical Christianity
2) Judaism
3) Satanic worship
 
Satan fools people, and there are a lot of names for the various
religions in the world, but they are ALL Satan's attempt to trick
and deceive people into taking ANY PATH they will personally believe
in away from Jesus Christ, away from the one true God, because even
the demons know that only Jesus Christ can save.
 
If you read the Bible, you'll come to understand all of this. You
will come to understand who God is, who you are, who Satan is, who
the demons are, and why sin is not tolerated in God's Kingdom, and
why Jesus came to take our sin away and restore us to that which
was lost when sin entered in and destroyed everything.
 
Even you need Jesus to forgive your sin. We all do (myself included).
 
--
Rick C. Hodgin
leigh.v.johnston@googlemail.com: Jan 22 04:14AM -0800

Interestingly on 5/12/17 you posted that Christianity wasn't a religion. Make your mind up you flake.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 22 05:18AM -0800

> Interestingly on 5/12/17 you posted that Christianity wasn't a religion. Make your mind up you flake.
 
I have explained this previously. It was probably in section you
labeled as "tl;dr".
 
Here's one from alt.os.development I posted recently:
 
https://groups.google.com/d/msg/alt.os.development/dCrzVEPYslI/5hhXeHjACAAJ
https://groups.google.com/d/msg/alt.os.development/dCrzVEPYslI/qCY_NbkYCQAJ
 
Summary:
 
The world can only see Christianity as a religion. It lumps all
faiths into the same category, because it sees them all equally
from only our flesh's point of view.
 
But for the one who is born again, we know the difference because
of our new spirit nature. We know the new relationship we have
with God and His Holy Spirit. We know whose we are, and where we
are going.
 
It is the augmented existence I tried to highlight on this post:
 
https://groups.google.com/forum/#!original/comp.lang.c++/885KFcqNYqk/6hnxLi1vBAAJ
 
That timeline on the right shows the combined simultaneous existence
of both our flesh and spirit once we come to Jesus, ask forgiveness
for our sin, and are saved. From that moment on, we are alive again
eternally. But here in this world, we still have to overcome much,
and it is a constant struggle against spiritual oppression.
 
--
Thank you! | Indianapolis, Indiana | God is love -- 1 John 4:7-9
Rick C. Hodgin | http://www.libsf.org/ | http://tinyurl.com/yaogvqhj
-------------------------------------------------------------------------
Software: LSA, LSC, Debi, RDC/CAlive, ES/1, ES/2, VJr, VFrP, Logician
Hardware: Arxoda Desktop CPU, Arxita Embedded CPU, Arlina Compute FPGA
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 22 05:21AM -0800

On Monday, January 22, 2018 at 8:18:25 AM UTC-5, Rick C. Hodgin wrote:
 
> It is the augmented existence I tried to highlight on this post:
 
> https://groups.google.com/forum/#!original/comp.lang.c++/885KFcqNYqk/6hnxLi1vBAAJ
 
> That timeline on the right shows the combined simultaneous existence
 
Should be "timeline on the left."
 
 
--
Thank you! | Indianapolis, Indiana | God is love -- 1 John 4:7-9
Rick C. Hodgin | http://www.libsf.org/ | http://tinyurl.com/yaogvqhj
-------------------------------------------------------------------------
Software: LSA, LSC, Debi, RDC/CAlive, ES/1, ES/2, VJr, VFrP, Logician
Hardware: Arxoda Desktop CPU, Arxita Embedded CPU, Arlina Compute FPGA
arnuld <sunrise@invalid.address>: Jan 22 04:43AM

AIM: To copy a file
PROBLEM: None
 
This runs fine, can this be improved. e.g getting rid of while() ?
 
 
#include <iostream>
#include <fstream>
 
int main()
{
char ch;
std::ifstream ifile("tree.c");
std::ofstream ofile("sample.c");
 
while(ifile.get(ch))
ofile.put(ch);
 
if(!ifile.eof() || !ofile)
std::cerr << "Something Happened\n";

return 0;
}
 
 
 
--
-- arnuld
http://lispmachine.wordpress.com/
Ian Collins <ian-news@hotmail.com>: Jan 22 05:52PM +1300

On 01/22/2018 05:43 PM, arnuld wrote:
> char ch;
> std::ifstream ifile("tree.c");
> std::ofstream ofile("sample.c");
 
ofile << ifile.rdbuf();
 
return 0;
}
 
--
Ian.
Real Troll <real.troll@trolls.com>: Jan 22 01:10AM -0400

On 22/01/2018 04:43, arnuld wrote:
> std::cerr << "Something Happened\n";
 
> return 0;
> }
 
You can use binary mode to handle all kinds of file. See this standard
Microsoft example Program:
 
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
#include <iostream>
#include <fstream>
 
const static int BUF_SIZE = 4096;
 
using std::ios_base;
 
int main(int argc, char** argv) {
 
std::ifstream in(argv[1],
ios_base::in | ios_base::binary); // Use binary mode so we can
std::ofstream out(argv[2], // handle all kinds of file
ios_base::out | ios_base::binary); // content.
 
// Make sure the streams opened okay...
 
char buf[BUF_SIZE];
 
do {
in.read(&buf[0], BUF_SIZE); // Read at most n bytes into
out.write(&buf[0], in.gcount()); // buf, then write the buf to
} while (in.gcount() > 0); // the output.
 
// Check streams for problems...
 
in.close();
out.close();
}
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
 
 
You need to close the stream to flush out the buffer otherwise you lose
data.
 
After you've compiled the file, you simply run at the command prompt
like this:
 
mycopy tree.c sample.c
 
mycopy is the name of the executable,
tree.c is your source file;
sample.c is your destination file;
arnuld <sunrise@invalid.address>: Jan 22 01:19PM

> On Mon, 22 Jan 2018 17:52:02 +1300, Ian Collins wrote:
 
> ofile << ifile.rdbuf();
 
Wow, so simple :) . Will use this.
 
End of section 15.14.3 of C++ Standard Library 2/e by Josuttis says this:
 
"Note that a stream buffer has no error state of its own. It also has no
knowledge of the input or the output stream that might connect to it. So,
calling:
 
out << in.rdbuf();
 
can't change the error state of \in\ due to a failure or end-of-file."
 
 
Is this a cause of concern ?
 
 
 
 
 
--
-- arnuld
http://lispmachine.wordpress.com/
scott@slp53.sl.home (Scott Lurndal): Jan 17 02:21PM


>>https://www.xquartz.org/
 
>There were also X Window System servers for the PC and X Terminals.
>Heck, there is an X Server application in the android store :)
 
There's an x-server and full set of x clients in cygwin, as well.
Ian Collins <ian-news@hotmail.com>: Jan 18 08:55PM +1300

On 01/18/2018 08:17 PM, Jorgen Grahn wrote:
> desktop environments, trying to create their own universes ...
 
> X11 did win, but I'm not sure it helped programmers and users that
> much.
 
It did to the extent that those of us working on more than one flavour
of UNIX could reuse code. It also gave rise to Motif on most UNIX
platforms.
 
--
Ian.
legalize+jeeves@mail.xmission.com (Richard): Jan 18 02:27AM

[Please do not mail me a copy of your followup]
 
"Fred.Zwarts" <F.Zwarts@KVI.nl> spake the secret code
 
>OpenVMS, once a popular OS, started with its own windowing system, but later
>moved to X-Windows.
 
Off the top of my head companies/proprietary window systems killed off
by the X Window System:
 
Sun's SunView
Sun's NeWS
SGI's 4Sight
SGI's MEX
DEC (DECwindows was their name for their X Window System
implementation, IIRC); I think you're right that they had a
proprietary thing before but I don't know what that was called.
Hewlett-Packard
Domain/OS from Apollo had something, I can't remember what it was called.
It might not have had a distinct name for the GUI part.
...and of course there are many smaller manufacturers that had their
own thing.
 
It's really quite successful that X managed to kill off all these
proprietary islands of functionality and unify them into a single
environment, both for users and developers.
--
"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>
Lynn McGuire <lynnmcguire5@gmail.com>: Jan 17 09:32PM -0600

On 1/17/2018 8:27 PM, Richard wrote:
 
> It's really quite successful that X managed to kill off all these
> proprietary islands of functionality and unify them into a single
> environment, both for users and developers.
 
The Apollo Domain windowing system was DM. It ran about 10X faster than
X Windows since it wrote straight to the hardware.
https://en.wikipedia.org/wiki/DM_(windowing_system)
 
Sun's SunView was actually pretty good.
 
Lynn
scott@slp53.sl.home (Scott Lurndal): Jan 18 02:34PM


>The Apollo Domain windowing system was DM. It ran about 10X faster than
>X Windows since it wrote straight to the hardware.
> https://en.wikipedia.org/wiki/DM_(windowing_system)
 
At the expense of network transparancy, one of the greatest
strengths (and weaknesses) of X11Rn.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jan 18 07:17AM

On Thu, 2018-01-18, Richard wrote:
 
> It's really quite successful that X managed to kill off all these
> proprietary islands of functionality and unify them into a single
> environment, both for users and developers.
 
On the other hand, the widget toolkits on top of X11 are quite
different in user interface and API. And then there's the various
desktop environments, trying to create their own universes ...
 
X11 did win, but I'm not sure it helped programmers and users that
much.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
"Fred.Zwarts" <F.Zwarts@KVI.nl>: Jan 18 09:50AM +0100

"Richard" schreef in bericht news:p3p0mj$m4m$1@news.xmission.com...
 
>implementation, IIRC); I think you're right that they had a
>proprietary thing before but I don't know what that was called.
>Hewlett-Packard
 
No, DECwindwos was the name of the X-Windows implementation. The native
Windowing system was called VWS (VAX Workstation Software) with its
programming interface UIS. It was much faster then DECwindows, but it was
not based on a client/server model.
http://h41379.www4.hpe.com/wizard/wiz_9916.html
Lynn McGuire <lynnmcguire5@gmail.com>: Jan 17 09:29PM -0600

On 1/17/2018 3:10 PM, Chris Vine wrote:
> Lynn McGuire <lynnmcguire5@gmail.com> wrote:
>> Auto will not work for function arguments.
 
> Unless its a lambda expression.
 
And you lost me.
 
Lynn
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 18 07:25AM +0100

On 1/18/2018 4:29 AM, Lynn McGuire wrote:
>>> Auto will not work for function arguments.
 
>> Unless its a lambda expression.
 
> And you lost me.
 
With a lambda you can write e.g.
 
auto const foo = []( auto& x ) { cout << x << endl; };
foo( "The answer is... " );
foo( 0b101010 );
 
It's roughly equivalent to this C++03 code:
 
struct Lambda_478
{
template< class Type >
void operator()( Type& x ) const { cout << x << endl; }
};
 
Lambda_478 const foo;
foo( "The answer is... " );
foo( 0b101010 );
 
 
Cheers & hth.,
 
- Alf
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Jan 17 09:10PM

On Tue, 16 Jan 2018 20:21:01 -0600
> Auto will not work for function arguments.
 
Unless its a lambda expression.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 18 07:27AM +0100

On 1/18/2018 7:25 AM, Alf P. Steinbach wrote:
 
>     Lambda_478 const foo;
>     foo( "The answer is... " );
>     foo( 0b101010 );
 
Oh wait. C++03 didn't have binary literals. Oops.
 
Cheers!,
 
- Alf
Cholo Lennon <chololennon@hotmail.com>: Jan 18 12:08PM -0300

On 12/01/18 15:03, Richard wrote:
> features. The same can be said for Catch2 compared to Google Test,
> which is the other dominant unit testing framework out there. It
> feels like Catch2 is gaining more adherents over time.
 
I don't know Catch2 (I'll take it a look!), but Boost.Test is really
simple, even for beginners:
 
// MyTest.cpp, compile with (just define BOOST_HOME env.var.):
// VC: cl /EHa /I%BOOST_HOME% MyTest.cpp
// gcc: g++ -I$BOOST_HOME MyTest.cpp -o MyTest
 
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp>
 
BOOST_AUTO_TEST_CASE(simpleTest)
{
// BOOST_REQUIRE_EQUAL(...
// BOOST_REQUIRE(...
// BOOST_FAIL(...
// BOOST_ERROR(...
// BOOST_REQUIRE_NE(...
// BOOST_REQUIRE_THROW(...
// BOOST_MESSAGE(...
// Etc.
}
 
struct MyFixture {
// ...
};
 
BOOST_FIXTURE_TEST_CASE(testWithFixture1, MyFixture)
{
// ...
}
 
BOOST_FIXTURE_TEST_CASE(testWithFixture2, MyFixture)
{
// ...
}
 
// end of MyTest.cpp
 
 
Regards
 
 
--
Cholo Lennon
Bs.As.
ARG
Manfred <invalid@invalid.add>: Jan 22 12:58AM +0100

On 01/21/2018 07:39 PM, James Kuyper wrote:
> However, I've run into a problem that is new to me, and I wasn't sure
> how to investigate further. One of these programs aborts under certain
> circumstances during an attempt to execute a delete expression.
 
I don't know if the following may apply, however:
The C++ runtime that implements new[] and delete[] must be the same - I
had this problem with libraries compiled with one version of the runtime
linked to a program using a different version.
Andrea Venturoli <ml.diespammer@netfence.it>: Jan 22 08:35AM +0100

On 01/21/18 21:27, James Kuyper wrote:
 
> produces too much information to make it easy to find the particular
> issue that's actually causing a problem, particularly on poorly written
> code like this.
 
I strongly disagree here.
While I'm not questioning your experience, mine was the opposite: every
time valgrind has brought something up, it was something that was worth
fixing.
Paavo Helde <myfirstname@osa.pri.ee>: Jan 22 11:07AM +0200

On 21.01.2018 22:36, James Kuyper wrote:
 
 
> I've thought of "fixing" this problem by doing such a re-write, but it
> would take a lot of time, and I was hoping that a more focused approach
> to debugging it would be possible.
 
If the bug is well reproducible, then it should be easy to find. If it
is always the same deallocation aborting, then first figure out where it
is allocated. Then put a breakpoint there, when reached it, put a data
breakpoint 4 or 8 bytes *before* the array, where the memory allocator
control block resides. Now continue the run and voila, the data
breakpoint ought to be triggered exactly by the culprit buffer overrun code.
 
If your program is multi-threaded then it becomes more tricky as the
memory allocations will become much more randomly placed and the
location of crash/abort will change all the time.
 
hth
Paavo
Robert Wessel <robertwessel2@yahoo.com>: Jan 22 03:58AM -0600

On Mon, 22 Jan 2018 08:35:49 +0100, Andrea Venturoli
>While I'm not questioning your experience, mine was the opposite: every
>time valgrind has brought something up, it was something that was worth
>fixing.
 
 
I'm going to have to agree with James here. The first time you use
something like Valgrind or Purify on a big piece of existing code
that's never gotten that treatment, is a lot like the first time a
decade old, million line project, gets linted.
 
You really don't want to be around for that if you can help it.
Besides, getting management to buy into months or years of effort to
eliminate the lint or Valgrind warnings that are "obviously" not
causing any problems in the field can be a challenge.
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: