If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.

Re: Pseudopointers

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.

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.

Re: Pseudopointers

Originally Posted by laserlight

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.

Re: Pseudopointers

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:

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,

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.

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.

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.

Re: Pseudopointers

@eightyfive

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.

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".

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!

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".

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

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.

Re: Pseudopointers

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

Originally Posted by eightyfive

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 ...

Re: Pseudopointers

Originally Posted by superbonzo

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

Re: Pseudopointers

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.

Originally Posted by eightyfive

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.

Originally Posted by eightyfive

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.

Originally Posted by eightyfive

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

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