Pseudopointers - Page 4
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 4 FirstFirst 1234
Results 46 to 56 of 56

Thread: Pseudopointers

  1. #46
    Join Date
    Feb 2013
    Posts
    26

    Re: Pseudopointers

    guys, I want to say that I understand what Paul said. Is not that the C/C++ language is unsafe, but is rather that undefined behavior can occur if the program/programmer is out of the specifications.
    A compiler might have bugs or not, but in this case we are talking about a code that does not meet specifications. That's why I decided to follow your suggestions, and had modified the code before to not take advantage of an unpredictable outcome, like if the 10 variables are stored contiguously. instead, something like an array or a structure must be used to make sure that this is enforced.

    I wanted to say this because , it's probably that some novice users can reach to this thread and I don't want them to get wrong information , confusion or examples of a bad programming practice. I think we all want this to not happen, since we are oriented to provide solutions not problems.

  2. #47
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Pseudopointers

    Quote Originally Posted by eightyfive
    you don't even know what bugs are we talking about, if not you probably can point to the specific line in one of the different codes that were exposed here, so you can show us what specific bug you want to remark. but you don't even know what code are you talking about. you just repeat the same things the others said
    You don't even know what is a compiler bug, otherwise you would not say that I "can point to the specific line in one of the different codes that were exposed here, so you can show us what specific bug you want to remark". Obviously, you did not find any compiler bugs, contrary to your claim. Please, I know what bugs have been discussed here, and if you think I have been merely repeating the same things that other have said with nothing added from my own, then you have not read my posts except to selectively take things out of context from your own ignorance.

    Quote Originally Posted by eightyfive
    like a troll, also is a postcounter++.
    An apt description of yourself.

    EDIT:
    Now that I have eaten dinner, I shall be a little more charitable: maybe it is not so much that you don't know what is a compiler bug, but rather because you are so quick to assume that people don't know what they are talking about that you missed my point that I saw no compiler bugs found by you, gave my reason, and implicitly invited you to explain what compiler bug you found.
    Last edited by laserlight; March 24th, 2013 at 07:52 AM.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #48
    Join Date
    Feb 2013
    Posts
    26

    Re: Pseudopointers

    Quote Originally Posted by laserlight View Post
    You don't even know what is a compiler bug, otherwise you would not say that I "can point to the specific line in one of the different codes that were exposed here, so you can show us what specific bug you want to remark". Obviously, you did not find any compiler bugs, contrary to your claim. Please, I know what bugs have been discussed here, and if you think I have been merely repeating the same things that other have said with nothing added from my own, then you have not read my posts except to selectively take things out of context from your own ignorance.


    An apt description of yourself.

    EDIT:
    Now that I have eaten dinner, I shall be a little more charitable: maybe it is not so much that you don't know what is a compiler bug, but rather because you are so quick to assume that people don't know what they are talking about that you missed my point that I saw no compiler bugs found by you, gave my reason, and implicitly invited you to explain what compiler bug you found.
    that's uncivil.
    You had a wrong interpretation there, because if you read correctly this post you can
    discover that I was talking about the bugs in the code, not about compiler bugs.
    compiler bugs are the ones inherent to the application itself (compiler).

    LOL , tried to be civil?.
    As you see I tried to be civil by stop arguing on things that I already understand,
    see my previous post.

    The problem was that you kept on repeating to me the same things again and again, and I told you already understood all that.

    You edited your post but I saw all those insults, nice user.
    Last edited by eightyfive; March 24th, 2013 at 08:08 AM.

  4. #49
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Pseudopointers

    Quote Originally Posted by eightyfive
    You had a wrong interpretation there, because if you read correctly this post you can
    discover that I was talking about the bugs in the code, not about compiler bugs.
    compiler bugs are the ones inherent to the application itself (compiler).
    In post #44, you wrote:
    Quote Originally Posted by eightyfive
    that's your story, and you say I'm a fool because I found some compiler bugs?
    is not my fault if those bugs are there, bugs that you didn't have idea of their existence,
    Quote Originally Posted by eightyfive
    LOL , tried to be civil?.
    As you see I tried to be civil by stop arguing on things that I already understand,
    Look at my previous posts. I never called you names. Then look at your post #46, and your other posts where you so quickly claimed that some other user was ignorant of something that they were talking about. So yes, you were not civil, hence I got angry when you so directly attacked me personally.

    Quote Originally Posted by eightyfive
    The problem was that you kept on repeating to me the same things again and again, and I told you already understood all that.
    If you don't seem to understand despite claiming to understand, then you should expect to be told over and over again until you demonstrate that you do understand. That said, in this case it looks like you simply used the wrong term by accident.

    Quote Originally Posted by eightyfive
    You edited your post but I saw all those insults, nice user.
    Yeah, I decided that those insults weren't called for. I may be angry, but that doesn't mean that responding in that way was the right thing to do. This is also why I then made one more edit after dinner, because I realised that perhaps you simply missed my point (which turns out to be closer to the mark that my own initial statement). If you don't want to receive insults, stop giving them.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #50
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Pseudopointers

    @eightyfive

    1. About a discussion (generally speaking)
      When a couple of experienced people (programmers and not only) disagree your point, the best thing you can do is to stop arguing, at least for a while, have a deep breath and think that for sure, there is something wrong in what you are talking about.
    2. About teaching others
      Try to teach beginners the good programming practices, rather than showing them "hacker style" code.
      In this case, point them to learn and understand the pointers arithmetic and do not "pseudopoint" to weird stuff like integers used as "pseudopointers".
    3. About your solution
      As you already said in the original post, "is a pile of junk".
      It may work but it's not generally guaranteed. In the programmers' jargon this called WOMM (Works On My Machine). One day, someone dealing with such code, may kill you for that. Keep it just for fun!
    4. About GOOGLE searching (see the original post)
      Try learning C++ from good manuals, good style programming guides and last but not the least, have a look in C++ standards each time something is unclear.
      GOOGLE isn't the best manual and is full of "junks".
    5. About discovering America (also, see the original post)
      It's nothing new under the Sun. You are not the first and probably not the last one, "dancing on a rope" in C++.
    Last edited by ovidiucucu; March 25th, 2013 at 04:39 AM. Reason: typos
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #51
    Join Date
    Feb 2013
    Posts
    26

    Re: Pseudopointers

    sorry for the delayed answer.. I was on my vacations XD

    well thanks for making a point @ovidiucucu

    let me tell you that I already noticed that some people that participated here
    are experienced somehow. For example Paul, he started not demostrating it by
    making some subjetive comments but later he shown he is experienced enough.
    It was really not my intention to disrespect him. so I apologize if that was the case.

    for example this guy @laserlight

    he doesn't seem to be experienced, since he only says useless things, mostly
    subjetive to me, but he wasn't capable of reading a source code still. he
    didn't read my code.

    @laserlight I don't really care if you are having breakfast or taking a ride, I would mostly
    care if you can read a source code and make objective comments on it.

    Let me tell you that now you have 3 working examples in my first post,
    I say it again, you have 3 codes and not 1.
    so you can't just say "your code doesn't work" because you would need to specify
    which one of the three.

    I know the 3 codes are working, let me explain to you the 3 codes.

    the first code was already discussed, it takes advantage or is exploiting the fact
    that some compilers, maybe all, maybe some, or whatever, are arranging 10 static global (and initialized)
    variables in a contiguous position, one next to the other.

    I know this behaviour is not specified in the C/C++ specifications, that was already
    discussed.

    For that reason, I dediced to follow your suggestions and went to make the other 2
    codes, which are using a 10-var struct and a 10-element array respectively, so you can be sure
    that the internal elements are stored contiguously.

    The code is portable (examples 2 and 3) since it takes into account the data size type and the pointer
    size type.

    Anyways, all this doesn't mean to be a library or something, is just a demostration
    on the pseudopointers.

    I understand now that this is maybe not for beginners , if so, it looks more like a "hack sytle" of coding, which doesn't characterize me.

    Regards
    Last edited by eightyfive; April 21st, 2013 at 07:31 AM.

  7. #52
    Join Date
    Oct 2008
    Posts
    1,168

    Re: Pseudopointers

    surprisingly (?), you not only insist on ignoring others' advice, you also keep saying wrong things proving poor understanding of basic programming facts:

    Quote Originally Posted by eightyfive View Post
    For that reason, I dediced to follow your suggestions and went to make the other 2
    codes, which are using a 10-var struct and a 10-element array respectively, so you can be sure
    that the internal elements are stored contiguously.

    The code is portable (examples 2 and 3) since it takes into account the data size type and the pointer
    size type.
    neither example "2" nor "3" is portable, the former mainly due to possible padding breaking the alleged contiguity of those ints, the latter due to the non portability of the assumption that arithmetic operations on integers are equivalent to the corresponding operations on pointers. BTW, note that both these observations have been already suggested to you many posts ago ...

  8. #53
    Join Date
    Feb 2013
    Posts
    26

    Re: Pseudopointers

    Quote Originally Posted by superbonzo View Post
    surprisingly (?), you not only insist on ignoring others' advice, you also keep saying wrong things proving poor understanding of basic programming facts:



    neither example "2" nor "3" is portable, the former mainly due to possible padding breaking the alleged contiguity of those ints, the latter due to the non portability of the assumption that arithmetic operations on integers are equivalent to the corresponding operations on pointers. BTW, note that both these observations have been already suggested to you many posts ago ...
    ignoring what? I don't insist or prove anything, I just said I followed his suggestions.. didn't you see that part? I used an array instead those 10 static global variables. so why you say I am ignoring something?

    and nobody did mention "padding" in a structure or an array so stop lying, or give me link to the comment since I don't want to loop through all those messages XD

    padding in an array? well that is new to me, but considering I'm a student I don't have to know everything at start, sure you are ignorant at some point if I ask you a couple of things...
    http://stackoverflow.com/questions/1...tween-elements
    http://www.daniweb.com/software-deve...dding-an-array
    http://computer-programming-forum.co...28164a3d8d.htm
    http://www.cplusplus.com/forum/beginner/50479/
    http://postimg.org/image/qsun6ojo/
    http://bytes.com/topic/c/answers/217456-array-padding

    the assumption that arithmetic operations on integers are equivalent to the corresponding operations on pointers
    ?? explain it better, maybe you can quote my code and explain it all better, I really don't want to figure it all out what you are saying because it could be nothing relevant after all.

    seriously, if you can quote here line by line, my examples 2 or 3, and tell me line by line what is this doing and remarking your point, that would be professional enough from your part.

    I won't be insisting in the portability of this, since you came with a concept that I didn't know

    Regards
    Last edited by eightyfive; April 21st, 2013 at 01:58 PM.

  9. #54
    Join Date
    Oct 2008
    Posts
    1,168

    Re: Pseudopointers

    you said

    Quote Originally Posted by eightyfive View Post
    I dediced to follow your suggestions and went to make the other 2
    codes, which are using a 10-var struct and a 10-element array respectively
    now, apparently the two examples appear reversed in post#1; obviously, the padding I referred to is of the struct example.

    Quote Originally Posted by eightyfive View Post
    explain it better
    given a pointer "T* p" and an integer type I with sizeof(I) >= sizeof(T*) then it's guaranteed that

    Code:
    reinterpret_cast<T*>( reinterpret_cast<I>( p ) ) == p
    always holds true. In other words, one can store a pointer in an integer and then convert back the integer to the pointer obtaining the original value.

    But, code like

    Code:
    reinterpret_cast<T*>( reinterpret_cast<I>( p ) + sizeof(T) ) == p + 1
    is NOT guaranteed to work on all platforms/compilers. In other words, in order to operate on integers as if they were pointers you need to make assumptions on the bit-representation of the pointer type; the latter is not fixed by the standard.

    Quote Originally Posted by eightyfive View Post
    give me link to the comment since I don't want to loop through all those messages XD
    struct binary layout has been mentioned in post#10 by OReubens, and the non-portability of integer arithmetic operations with pointer conversions has been mentioned by myself in post#38.

    Quote Originally Posted by eightyfive View Post
    ignoring what?
    please, reread carefully ovidiucucu's last post, especially the first point ...
    Last edited by superbonzo; April 22nd, 2013 at 03:03 AM. Reason: typo in pointer expression

  10. #55
    Join Date
    Feb 2013
    Posts
    26

    Re: Pseudopointers

    alright, I will

    ex.2
    Code:
    #define XPOINTERTYPE unsigned long
    #define XVARTYPE int
    
    	unsigned char OFFS = (unsigned char)sizeof(XVARTYPE);// Up to 255
    	XPOINTERTYPE entradaX=(XPOINTERTYPE)&entradas[0];// Una especie de puntero THIS
    	XPOINTERTYPE inicio_bloque=(XPOINTERTYPE)&entradas[0];
    	XPOINTERTYPE fin_bloque=(XPOINTERTYPE)&entradas[9];
    ex.3
    Code:
    #define XPOINTERTYPE unsigned long
    #define XVARTYPE int
    
    	unsigned char OFFS = (unsigned char)sizeof(XVARTYPE);// Up to 255
    	XPOINTERTYPE entradaX=(XPOINTERTYPE)&entradas.a;// Una especie de puntero THIS
    	XPOINTERTYPE inicio_bloque=(XPOINTERTYPE)&entradas.a;
    	XPOINTERTYPE fin_bloque=(XPOINTERTYPE)&entradas.j;
    I wanted to arrange for portability issues using 2 datatypes for VALUE operations and for POINTER operations, you see those definitions (XVARTYPE and XPOINTERTYPE) for each situation.
    and definition 'OFFS' will hold the correct offset to displace along every entry of the structure in memory. (it uses sizeof to enforce the correct value in different platforms). I'm just telling you what was my workaround for the compatibility issue.
    but I didn't consider the padding in a struct, and not even know that of padding in arrays (you gave that information).
    So, that was just my attempt, but as I told you, I won't insist defending the portability of my examples.
    thanks for your time.
    Regards
    Last edited by eightyfive; April 21st, 2013 at 08:19 PM.

  11. #56
    Join Date
    Oct 2008
    Posts
    1,168

    Re: Pseudopointers

    Quote Originally Posted by eightyfive View Post
    but I didn't consider the padding in a struct, and not even know that of padding in arrays (you gave that information)
    just to clarify, as I pointed out in the beginning of my last post above, I never said that arrays can have padding, only structs can have padding.

Page 4 of 4 FirstFirst 1234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center