1

Topic: Error: at pointer type coercion the pointer is lost!

In template class wrote simple function which I cause for object specified by type unsigned int32_t

#include <cstdint>
#include "MyLib/Memory.h"
template <class type>
class allocator final
{
public:
type* AllocationMemory (std:: size_t NeedSize) const
{
void* p = nullptr;
type* Memory = nullptr;
p = MyLib:: AllocationMemory (NeedSize);//p always has type void* and after performance of this line value 0x7fffd80389b0
Memory = (type *) p;//Memory before performance of this line has type unsigned int *, and right after executions - unsigned int and value 0!!!
return Memory;
}
};

In file Memory.cpp:

void* MyLib:: AllocationMemory (csize_t Size)
{
void* Memory = malloc (Size);
if (! Memory) throw std:: bad_alloc ();
return Memory;
}

Why the pointer turns in normal int???

2

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

//Memory before performance of this line has type unsigned int *, and right after executions - unsigned int and value 0!!!
Why the pointer turns in normal int???

It is a bug in yours QtCreator in

3

Re: Error: at pointer type coercion the pointer is lost!

NekZ wrote:

it is passed...
It is a bug in yours QtCreator in

At me this problem turns out both in debugging, and in release, and for GCC and Intel - compilers with a key-O0

4

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL;
I meant that at QtCreator' there is such bug when you in it , suddenly at a variable can exchange type.

5

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL;
Where that you say lies, all works.
http://cpp.sh/5a6vw

6

Re: Error: at pointer type coercion the pointer is lost!

NekZ wrote:

AlekseySQL;
I meant that at QtCreator' there is such bug when you in it , suddenly at a variable can exchange type.

So I unsubscribed that it not only in . At me the program from - for it falls out.

7

Re: Error: at pointer type coercion the pointer is lost!

Any horror films for the night. All life in a C of pointers could be appropriated each other easy.
What there can spoils? Copying of 32 (64) bits from one variable in another is simple. But it is quite possible that the variable spoils somewhere in other place.
If there is a simple test a case on which the error is played back it would be possible to talk.
IMHO AND AFAIK

8

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL, and what for so many senseless variables and  in function allocator:: AllocationMemory?

9

Re: Error: at pointer type coercion the pointer is lost!

egorych wrote:

AlekseySQL, and what for so many senseless variables and  in function allocator:: AllocationMemory?

To understand in what operation there is an error. I, by the way, tried static_cast -  an error.
It was launched under devilish Win10: Qt Creator c MinGW32 shows the same focus. So I want to try in a Visual Studio with compilers of Intel and MSVC, but I am afraid that the force nayward is final absorbs me.

10

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

I am afraid that the force nayward is final absorbs me.

it is heavy to search for a black cat in a dark room, especially when it there is not present)) but all of us equally will)) an error at you not here, obviously

11

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

to understand in what operation there is an error. I, by the way, tried static_cast - the same error.

And sense? Type coercion in si-style, it, as a matter of fact also is static_cast. For coercion from void* to other pointer type, try reinterpret_cast.

Memory = reinterpret_cast <type *> (p);

12

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

it is passed...
So I unsubscribed that it not only in . At me the program from - for it falls out.

Your program falls out NOT  it.

13

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

In template class wrote simple function which I cause for object specified by type unsigned int32_t

#include <cstdint>
#include "MyLib/Memory.h"
template <class type>
class allocator final
{
public:
type* AllocationMemory (std:: size_t NeedSize) const
{
void* p = nullptr;
type* Memory = nullptr;
p = MyLib:: AllocationMemory (NeedSize);//p always has type void* and after performance of this line value 0x7fffd80389b0
Memory = (type *) p;//Memory before performance of this line has type unsigned int *, and right after executions - unsigned int and value 0!!!
return Memory;
}
};

In file Memory.cpp:

void* MyLib:: AllocationMemory (csize_t Size)
{
void* Memory = malloc (Size);
if (! Memory) throw std:: bad_alloc ();
return Memory;
}

Why the pointer turns in normal int???

Idea too any foolish.
We select storage under type type?
But suddenly other size, than sizeof (type) !
About as, to spite of all enemies!

14

Re: Error: at pointer type coercion the pointer is lost!

MasterZiv wrote:

idea too any foolish.
We select storage under type type?
But suddenly other size, than sizeof (type) !
About as, to spite of all enemies!

I already simplified it to a limit to find an error. Actually it is selected under an array of elements of type type so in the real task there is a multiplication of the size on an amount of elements.

15

Re: Error: at pointer type coercion the pointer is lost!

MasterZiv wrote:

Your program falls out NOT  it.

From - for wrong coercion On the second iteration 0 byte of storage and the program is selected falls out at reversal to this section. So from - for it.
Other question that an error most likely sits in other place, in already fulfilled code which so unusually shows itself. I tried to search for Intel Inspector - an ohm but while it is ineffectual.
What searching tools of errors are?

16

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

What there are searching tools of errors?

In a broad gull to write or to the console. After each line you interpose an output of the necessary variables, then you study.
on symptoms it is similar that at you storage spoils any code.

17

Re: Error: at pointer type coercion the pointer is lost!

+ And the coolest when I commented out a line with storage selection (and reading from a file in this storage) the program perfectly works (truth with the zero data) without an error. Intel Inspector continues to write about an internal error and with this error asks to address to developers of a product (i.e. to Intel).

18

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

+ And the coolest when I commented out a line with storage selection (and reading from a file in this storage) the program perfectly works (truth with the zero data) without an error.

Try  handling, i.e. to leave only storage selection.

19

Re: Error: at pointer type coercion the pointer is lost!

If itself you can not find in what a problem: try to make the small project repeating your error and here lay out.
The project, instead of code pieces is necessary, it was possible to launch.
PS it is normal in the course of writing of demonstration of a problem the understanding of its reason comes.

20

Re: Error: at pointer type coercion the pointer is lost!

All thanks, the error is found!
To drift on a piece of storage I added pointerful Data (type type) not an amount of elements and the size:

std:: size_t SizeOfData = Quantity * sizeof (Type);
CurrentAllocator->ReadAllocatorFromMemory ((void *) (Data + SizeOfData));

Therefore the program fell outside the limits storage.
And the debugger by good operation of the program and continued to show instead of the pointer any not clear values int (that confused me). As far as I understand it is a problem  GDB, but intel parallel studio, unfortunately, contains also only GDB (similar they do not have own debugger). So to replace with something another it did not turn out.

21

Re: Error: at pointer type coercion the pointer is lost!

AlekseySQL wrote:

it is passed...
From - for wrong coercion On the second iteration 0 byte of storage and the program is selected falls out at reversal to this section. So from - for it.
Other question that an error most likely sits in other place, in already fulfilled code which so unusually shows itself. I tried to search for Intel Inspector - an ohm but while it is ineffectual.
What searching tools of errors are?

Debugger, the debug press, broad gulls, head.