-
March 24th, 2013, 12:28 AM
#46
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.
-
March 24th, 2013, 05:54 AM
#47
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.
Last edited by laserlight; March 24th, 2013 at 06:52 AM.
-
March 24th, 2013, 07:01 AM
#48
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.
You edited your post but I saw all those insults, nice user.
Last edited by eightyfive; March 24th, 2013 at 07:08 AM.
-
March 24th, 2013, 07:20 AM
#49
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.
-
March 25th, 2013, 01:47 AM
#50
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 03:39 AM.
Reason: typos
-
April 21st, 2013, 06:22 AM
#51
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 06:31 AM.
-
April 21st, 2013, 09:16 AM
#52
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 ...
-
April 21st, 2013, 12:33 PM
#53
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
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 12:58 PM.
-
April 21st, 2013, 02:41 PM
#54
Re: Pseudopointers
you said
Originally Posted by eightyfive
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 02:03 AM.
Reason: typo in pointer expression
-
April 21st, 2013, 07:08 PM
#55
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 07:19 PM.
-
April 22nd, 2013, 02:08 AM
#56
Re: Pseudopointers
Originally Posted by eightyfive
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|