Monday, January 9, 2017

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

Ramine <toto@toto.net>: Jan 09 11:36AM -0800

Hello.....
 
My C++ synchronization objects library was just updated again...
 
 
SafeInt is only compatible with Visual C++ and GCC and Clang.
 
So i have added a test3.cpp example that is compatible with C++ Builder,
you will find it inside the LW_SemaMonitor directory and SemaMonitor
directory with the makefiles: makefile.bor32 and makefile.bor64.
 
 
You can download again my new updated C++ synchronization objects
library from:
 
https://sites.google.com/site/aminer68/c-synchronization-objects-library
 
 
 
Thank you,
Amine Moulay Ramdane.
Veek M <vek.m1234@gmail.com>: Jan 09 11:12AM +0530

http://storage2.static.itmages.com/i/17/0109/h_1483938906_5595082_7e973c6bd8.png
 
He says that:
1. 'goal of never allocating storage fails with complicated structures'
 
What does he mean by complicated structure? Is he talking about 'struct'
or a constant expression that's weird?
 
2. 'const definitions must default to internal linkage' 'linker errors
would occur with complicated consts because they cause storage to be
allocated in multiple cpp files. The linker would see the same
definition in multiple object files, and complain'
 
How? It's only a definition when a value is assigned. Therefore if C++
did default to external storage, ONLY WHEN I DID:
 
const int i = 10;
would there be conflict IF it was used in multiple files (.c)
 
If i just did:
const int i;
and C++ defaults to external storage this would be great because I
wouldn't need 'extern' and it would automagically link to whichever file
had the definition.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 09 11:16AM +0100

On 09.01.2017 06:42, Veek M wrote:
> 1. 'goal of never allocating storage fails with complicated structures'
 
> What does he mean by complicated structure? Is he talking about 'struct'
> or a constant expression that's weird?
 
A goal of never allocating storage appears to be a goal of defining a
name for a value so that the compiler can inline use of that value
instead of referring to a memory location where the value is stored.
 
In modern C++ this can be expressed with `constexpr`.
 
`constexpr` can't handle e.g. a `std::string`, because it uses dynamic
allocation which necessarily is done at run-time, while the `constexpr`
mechanism is entirely compile time.
 
 
> and C++ defaults to external storage this would be great because I
> wouldn't need 'extern' and it would automagically link to whichever file
> had the definition.
 
You can't do the latter, it won't compile.
 
But I'm not sure what Bruce is talking about here, I think I'd have to
look that up in context to get some traction on it.
 
 
Possibly relevant: Monthy Python's sketch about Bruce the Australian.
<url: https://www.youtube.com/watch?v=bNBy1D1Y0h4>
 
Cheers!,
 
- Alf
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Jan 05 11:09AM

On Thu, 5 Jan 2017 01:41:46 -0500
 
> Why would the the "T" object be constructed repeatedly? In the
> "get_ref" function the struct "init" is only instantiated once and is
> declared with static storage duration.
 
Yes, you are right about that.
 
> for (size_t i = 0; i < 10; ++i) { b.print_it(); }
> return 0;
> }
 
Yes that looks OK. Function statics avoid both the issues that you ran
into (the absence of a definition and use before initialization).
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Jan 05 01:13AM

On Wed, 4 Jan 2017 17:18:06 -0500
> within the initializer list, even though _buf is instantiated within
> the constructor. I imagine there is something somewhere in the
> standard which says I am wrong.
 
If is ODR-used, then it must be defined. In addition, in your usage it
also needs to be initialized before first use. See below.

> init() : _ref(new (_buf) T()) {
> _buf = new char[sizeof(T)];
> }

The first time you call get_ref(), you use placement new in the member
initializer list before the block of memory pointed to by 'buf' has
been allocated in the constructor. Surely you get a segfault with gcc
(which you say makes the mistake of trying to compile and link it)?
 
(Apart from that, the code cannot possibly serve any useful purpose
because every time print_it() is called after that first time, a 'T'
object will be constructed in the formerly allocated memory, but then
immediately be replaced by reallocated memory in the constructor
which will have no object constructed in it. In consequence, you have
a memory leak, and you also have a second round of undefined behavior by
the call to the Foo::print_it() non-static method on a Foo object which
does not exist.)
 
bitrex <bitrex@de.lete.earthlink.net>: Jan 04 05:18PM -0500

The following snippet compiles with no warnings under GCC on Compiler
Explorer, while Clang warns on the line "init() : _ref(new (_buf) T())"
that "warning: instantiation of variable 'Bar<Foo>::_buf' required here,
but no definition is available [-Wundefined-var-template]"
 
When attempting to run the code on Ideone it fails with a linker error
about an undefined reference on the same line.
 
Is there a way to make a hack like this work "properly", i.e. have
get_ref() return a reference a templated class where "placement new" has
been used to instantiate the class on a static buffer, without resorting
to initializing the static field for the buffer outside the class
definition?
 
I would have thought that since _buf had static storage duration that I
could use placement new to initialize the const-qualified pointer within
the initializer list, even though _buf is instantiated within the
constructor. I imagine there is something somewhere in the standard
which says I am wrong.
 
#include <cstddef>
#include <iostream>
#include <new>
 
struct Foo {
Foo() = default;
void print_it() {
std::cout << "hey hey hi" << std::endl;
}
};
 
template <typename T>
class Bar
{
public:
Bar() = default;
~Bar() = default;
 
void print_it()
{
get_ref().print_it();
}
 
private:
static char* _buf;
 
static T& get_ref() {
struct init {
public:
init() : _ref(new (_buf) T()) {
_buf = new char[sizeof(T)];
}
 
operator T*() const {return _ref; }
 
private:
T *const _ref;
};
 
static init _init;
return *_init;
}
};
 
int main ()
{
auto b = Bar<Foo>();
b.print_it();
return 0;
}
Wouter van Ooijen <wouter@voti.nl>: Jan 03 07:41PM +0100

Op 03-Jan-17 om 6:13 PM schreef Daniel:
> I'm currently using the boost unit test framework for a project that doesn't otherwise depend on boost. The features that I'm using are BOOST_REQUIRE, BOOST_CHECK, BOOST_REQUIRE_EXCEPTION, BOOST_CHECK_EXCEPTION, and checking that there are no memory leaks.
 
> It's proving too difficult if not impossible to set up continuous integration builds for all the environments and compilers supported that link to boost, so I'm looking for a self-contained replacement that can be included in the distribution. I looked at Catch https://github.com/philsquared/Catch, but it tries to be too clever, resulting in too many issues.
 
> Any suggestions?
 
google test?
catch?
 
Wouter "Objects? No Thanks!" van Ooijen
Jeff-Relf.Me <@.>: Jan 04 10:26PM -0800

chrisv <chrisv@nospam.invalid>: Jan 03 07:32AM -0600

Peter Köhlmann wrote:
 
>> if ( Level = BB_Fast - BB_Slow, TopFlags, TopMatch = !S && !_S
>> ) {
 
> Ye gods!
 
If "Ezekiel" was here, and you said that the above code was crap, he
would demand "facts and a code analysis". LOL
 
The kreep even claimed that it was "ignorant" to say that Relf's
statements eschewing the importance of compliler warnings were
"stupid".
 
I couldn't make this stuff up!
 
Ezekreep was a trolling fsckwit, if ever there was one. Apparently,
he thought that he could beat us with his lies.
 
--
"For some reason the mindless droids here equate anything open source
with somehow being technically superior." - trolling fsckwit
"Ezekiel", lying shamelessly
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 03 11:09AM +0100

> int b = obj.var<int>;
 
> return 0;
> }
 
[example]
 
[C:\my\forums\clc++\047]
> g++ --version | find "++"
g++ (tdm64-1) 5.1.0
 
[C:\my\forums\clc++\047]
> g++ foo.cpp -Wno-unused-variable
foo.cpp: In function 'int main()':
foo.cpp:11:17: error: 'var' is not a member template function
int b = obj.var<int>;
^
 
[C:\my\forums\clc++\047]
> cl /nologo- 2>&1 | find "++"
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23725 for x86
 
[C:\my\forums\clc++\047]
> cl foo.cpp /wd4189 /wd4101
foo.cpp
 
[C:\my\forums\clc++\047]
> _
[/example]
 
Neither compiler has a problem with a template /function/ accessed this
way, so it's evidently about template variables being A New Thing™.
 
Note: while the MSVC compiler is current, the g++ compiler used here is
old; I believe the current version is 6.1 or something like that.
 
Cheers & hth.,
 
- Alf
Veek M <vek.m1234@gmail.com>: Jan 09 11:48AM +0530

Basically he says:
'a compiler will not be sophisticated enough to keep an aggregate in its
symbol table'
 
surely if it's a local aggregate, that's a SP operation and if it's
global then it's in the file.o
 
He's basically trying to make the point that a 'const' can be used with
aggregates (array, struct, union) but only for immutablity (can't alter)
and NOT for constant folding (compiler substitution).
 
But a symbol table stores identifiers and type info not the actual value
so I was wondering what he meant by compiler sophistication?
Veek M <vek.m1234@gmail.com>: Jan 09 11:58AM +0530

Veek M wrote:
 
> alter) and NOT for constant folding (compiler substitution).
 
> But a symbol table stores identifiers and type info not the actual
> value so I was wondering what he meant by compiler sophistication?
 
I do understand that he could store simple values (#define equivalent)
in the symbol table and work with that to do simple arithmetic
computations to allocate arrays.
 
So, const int i = 10; could be defined in ST and never hit the file for
allocation if you obey certain rules (not take an address, don't use
extern for external linkage) but I was hoping someone could shed more
light on 'compiler will not be sophisticated' - hashes and BST are not
all that complicated so.. what does he mean by 'sophisticated'. What
prevents him from allocating an array and indexing it and allowing:
 
float f[ i[2] ];
Ramine <toto@toto.net>: Jan 08 06:37PM -0800

Hello.....
 
My C++ synchronization objects library was just updated...
 
 
I have just used the following SafeInt 3.0.18:
 
http://safeint.codeplex.com/releases/view/125522
 
It is a clever library and method to detect and prevent overflow and
underflow on datatypes such as char, signed and unsigned integer, and
signed and unsigned long long integer etc. , i have just included it
inside the SemaMonitor directory inside the zip and i have showed you
how to use it, just look at how to use it inside the test1.cpp example
inside the zip file inside the SemaMonitor directory...
 
 
You can download again my C++ synchronization objects library from:
 
https://sites.google.com/site/aminer68/c-synchronization-objects-library
 
 
About SemaMonitor 2.02...
 
When you use Semaphores , and when you release and you have attained the
maximum count to be released, the signal(or the release) will be lost
and this is no good, this is why i have implemented my new algorithm of
my SemaMonitor version 2.02, now if you want the signal(s) to not be
lost with my SemaMonitor, you can configure it by passing a parameter to
the constructor, and it works great, this has helped to implement my
Concurrent FIFO Queue 1 and my Concurrent FIFO queue 2 without using
Condition variables.
 
You can download the concurrent FIFO queues from:
 
 
https://sites.google.com/site/aminer68/concurrent-fifo-queue-1
 
and from:
 
https://sites.google.com/site/aminer68/concurrent-fifo-queue-2
 
 
And you can download my Lightweight SemaMonitor and my SemaCondvar
version 2.02 from:
 
Lightweight SemaCondvar & SemaMonitor version 2.02
 
https://sites.google.com/site/aminer68/light-weight-semacondvar-semamonitor
 
And:
 
SemaCondvar & SemaMonitor version 2.02
 
https://sites.google.com/site/aminer68/semacondvar-semamonitor
 
 
Thank you,
Amine Moulay Ramdane.
Ramine <toto@toto.net>: Jan 08 06:24PM -0800

Hello....
 
I advice you to use this Easy to use C++ memory leak detection library
 
http://www.neoegm.com/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/
 
And also i advice you to use this SafeInt 3.0.18 C++ library to detect
and prevent overflow and underflow on datatypes such as char, signed and
unsigned integer, and signed and unsigned long long integer etc.
 
 
http://safeint.codeplex.com/releases/view/125522
 
 
I am using them and they are good.
 
 
Thank you,
Amine Moulay Ramdane.
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: