26

Re: Whether safely to appropriate one pointer to another?.

Hello, Croessmah, you wrote:> If I correctly understood a C, you came across indefinite behavior at conversion of pointers: the Citation from the standard concerns to objects under construction or destruction: "[class.base.init] and [class.cdtor] (quoted) describe the behavior of objects during the construction and destruction phases" - (http://eel.is/c++draft/basic.life#4.sentence-4) I do not say that there not UB, but the citation not that since there conversion of pointers was not during creation or object removal.

27

Re: Whether safely to appropriate one pointer to another?.

Absolutely safely except for a case pointerful on the virtual function which has the perverted type. Problems can arise exceptional during the moment . Moreover, the given operation  and accordingly  on any architecture at which the size of pointer type less or is equal to digit capacity of the processor. Probably on some other that, but it it is necessary to look the documentation. So it is possible to use  except for artful embeded systems at which storage it is addressed on banks. But correctly such operation  TypeA * a; TypeB * b; a=reinterpret_cast <TypeA *> (b); Because at simple equating for pointers on related classes the mysterious address magic which demands their possibility  starts to work.

28

Re: Whether safely to appropriate one pointer to another?.

Hello, okman, you wrote: O> Or such assignment is always safe, even if pointers contain null or "garbage"? The answer within the limits of existing systems - it is safe. The answer formal - is not present. Because the pointer is not the address generally, and only something such, application to which  gives to operation access to object in which he specifies. The mechanism of it  can be any basically. Therefore and the mechanism of copying of the pointer can be basically any so, and to comprise any checks which do not transit at incorrect assignment. All it is very far from a reality and is purely speculative. But not it is impossible basically.

29

Re: Whether safely to appropriate one pointer to another?.

Hello, Pavel Dvorkin, you wrote: PD> Hello, okman, you wrote: O>> Or such assignment is always safe, even if pointers contain null or "garbage"? PD> the Answer within the limits of existing systems - it is safe. http://rsdn.org/forum/cpp.applied/7090690.1 the author: okman Date: 23.03 09:10

30

Re: Whether safely to appropriate one pointer to another?.

Hello, AlexGin, you wrote: AG>... AG> we Tell so: it is far not (void *), and more difficult type - here is how the first parameter in _beginthread: AG>... Fairly read all links. Something on my question will be? Interests, for example, to that it should be equal sizeof the pointer on a method?

31

Re: Whether safely to appropriate one pointer to another?.

Hello, okman, you wrote: O> As think, whether it is possible in a C or a C ++ to receive any ghost effect during O> assignment of one pointer to another? If the receiver is badly aligned, it UB and in practice leads bus error . I already read your example, . Simply decided to replenish set of variants

32

Re: Whether safely to appropriate one pointer to another?.

33

Re: Whether safely to appropriate one pointer to another?.

34

Re: Whether safely to appropriate one pointer to another?.

Hello, SaZ, you wrote: SaZ> Fairly read all links. Something on my question will be? Like above, in my answer, was on your question (apropos void *). SaZ> Interests, for example, to that it should be equal sizeof the pointer on a method? sizeof the pointer on a method - same, as sizeof (int *); in general - sizeof same, as at all other pointers in applications of the given architecture (that is 4 bytes for x86; 8 byte for x64). class Foo {public: int f (string str) {std:: cout <<"Foo:: f ()" <<std:: endl; return 1;}}; int main () {int (Foo::*fptr) (string) = &Foo::f; std:: cout <<"sizeof-fptr =" <<sizeof (fptr) <<std:: endl;... return 0;} P.S. Here once again I give the same useful reference: https://www.codeguru.com/cpp/cpp/articl … nction.htm more sensible description on the given subject - I did not see.

35

Re: Whether safely to appropriate one pointer to another?.

Hello, AlexGin, you wrote: AG> AG> sizeof the pointer on a method - same, as sizeof (int *); AG> in general - sizeof same, as at all other pointers in applications of the given architecture (that is 4 bytes for x86; 8 byte for x64). It is possible not so without adducing any proof? AG> P.S. Here once again I give the same useful reference: AG> https://www.codeguru.com/cpp/cpp/articl … nction.htm AG> more sensible description on the given subject - I did not see. Once again. I read links. It is not necessary to double them on 100 times. Better here it explain: https://ideone.com/3WjDKl #include <iostream> #include <string> struct A {virtual void f () = 0;}; struct B: A {void f () override {}}; int main () {const auto p = &B::f; const bool ok = sizeof (void *) == sizeof (p); if (! ok) std:: cout <<"Not OK"; return 0;}

36

Re: Whether safely to appropriate one pointer to another?.

Hello, AlexGin, you wrote: SaZ>> Fairly read all links. Something on my question will be? AG> like above, in my answer, was on your question (apropos void *). SaZ>> Interests, for example, to that it should be equal sizeof the pointer on a method? AG> AG> sizeof the pointer on a method - same, as sizeof (int *); AG> in general - sizeof same, as at all other pointers in applications of the given architecture (that is 4 bytes for x86; 8 byte for x64). It not so. At least at old studios under 32 bits this size was 8. Pointerful on an ordinary function too any warranties that was not possible safely to void* .

37

Re: Whether safely to appropriate one pointer to another?.

Hello, SaZ, you wrote:... SaZ> it is better here explain: SaZ> https://ideone.com/3WjDKl... Costs on-line ideone.com At me in MSVC2015 #include "stdafx.h" #include <iostream> #include <string> struct A {virtual void f () = 0;}; struct B: A {void f () override {}}; int main () {const auto p = &B::f; const bool ok = sizeof (void *) == sizeof (p); if (! ok) std:: cout <<"Not OK"; std:: cout <<"sizeof (void *) =" <<sizeof (void *) <<std:: endl; std:: cout <<"sizeof (p) =" <<sizeof (p) <<std:: endl; getchar (); return 0;} Output for MSVC2015 (x86): sizeof (void *) = 4 sizeof (p) = 4 Output for MSVC2015 (x64): sizeof (void *) = 8 sizeof (p) = 8 I Trust studio! An output for http://rextester.com/l/cpp_online_compiler_visual sizeof (void *) = 8 sizeof (p) = 8 Here (in cpp_online_compiler_visual) also like logical. An output for ideone.com: similarly for https://wandbox.org: similarly for http://cpp.sh (in mode Cpp-11): Not OKsizeof (void *) = 8 sizeof (p) = 16 About http://rextester.com: cpp_online_compiler_gcc also: and cpp_online_compiler_clang: Not OKsizeof (void *) = 8 sizeof (p) = 16 it is strange... At least, I here do not have logical explanation.

38

Re: Whether safely to appropriate one pointer to another?.

Hello, night beast, you wrote: NB> Hello, AlexGin, you wrote: SaZ>>> Fairly read all links. Something on my question will be? AG>> like above, in my answer, was on your question (apropos void *). SaZ>>> Interests, for example, to that it should be equal sizeof the pointer on a method? AG>> AG>> sizeof the pointer on a method - same, as sizeof (int *); AG>> in general - sizeof same, as at all other pointers in applications of the given architecture (that is 4 bytes for x86; 8 byte for x64). NB> it not so. I here resulted examples for MSVC2015 - all quite logically (the sizes of pointers are identical). Here I near at hand do not have other studio (I will check up under MSVC2008 at home, but more ancient I will not find). NB> at least at old studios under 32 bits this size was 8. NB> pointerful on an ordinary function too any warranties that was not possible safely to void* . Where though any explanation to the given phenomenon? The pointer is an address in storage. How it can have different dimensionalities in the same process?

39

Re: Whether safely to appropriate one pointer to another?.

Hello, AlexGin, you wrote: AG> As it can have different dimensionalities in the same process? I recommend to perusal: https://stackoverflow.com/questions/160 … on-pointer