4 ms·
The char* cast there makes it explicit what the decrement operator does here: it decrements hash_ptr.parm.v.p by one because the value is treated as a pointer t
by pavlov 5y ago
The char* cast there makes it explicit what the decrement operator does here: it decrements hash_ptr.parm.v.p by one because the value is treated as a pointer to char.
Maybe the problem is that fpop() returns something else than a char?
- mikewarot 5y agoSo it decrements the pointer by 1, then uses that updated pointer to store a character in memory (the outer *)?
- NonEUCitizen 5y agoYup. -- decrements by 1 * sizeof(type_being_pointed_to) bytes. Since the pointer was cast to (char *) first, the type being pointed to is char, which is 1 byte on most systems. As others have mentioned, take some time to learn C on its own -- it will make the porting effort go faster, and serve you well generally. Have you read "The C Programming Language" by Brian Kernighan and Dennis Ritchie? (but unless that code base is really old, I suggest later-than-first edition)
- NonEUCitizen 5y agoIn your mind, you can expand the code to make it clearer: char *p; p = --(char*)hash_ptr.parm.v.p; *p = fpop(sst);
- sargstuff 5y ago(char) cast looks like being used for address alignment. Need to check what address alignment for target environment is and change the cast to appropriate alignment. aka sparc addresses are not 8 bit aligned! hash_ptr.parm.v.p points to top of sst stack containing an 8 bit aligned pointer address. p == ---(.....) gets address to pop off stack. missing a step/statement. sst needs to be in struc address given by p. aka hash_ptr.parm.v.sst p should then point to the result of fpop(hash_ptr.parm.v.sst
- zoomablemind 5y agofpop() is a typed-pop and yields a float from the value union. This design also uses float storage for any number including integers. So in the code fragment above, it seems that the fpop() number is saved into a character value (apparently with some certitude that it should fit into char type) at some pointer destination in what seems to be an array of chars.
- tom_ 5y agoThe operand of -- must be a modifiable lvalue. The result of a cast is never an lvalue. EDIT: This might be use of generalized lvalues: https://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Lvalues.html https://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Lvalues.html - latest gcc manual doesn't mention it though, so perhaps it's been removed?
- fhars 5y agoYes,it is gone since gcc-4.