4 ms·
Probably do the same thing that the Linux Kernel did when it wanted to move to a newer version of C.[0] Make the change, see what breaks. [0] https://lwn.net/A
by AdmiralAsshat 5y ago
Probably do the same thing that the Linux Kernel did when it wanted to move to a newer version of C.[0] Make the change, see what breaks.
[0] https://lwn.net/Articles/885941/ https://lwn.net/Articles/885941/
- mikewarot 5y agoI've been trying to do that... but the code is so opaque in terms of pointers and pointer math that I can't really tell what's going on. Example: *(--(char*)hash_ptr.parm.v.p) = fpop(sst); I know that pointer math in C is weird, and increment/decrement aren't necessarily +/- 1, but rather the size of the object pointed to??? THis is one of the first things that blows up when you compile it with a modern gcc. src/words.c - line 2012
- pavlov 5y agoThe 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.
- dllthomas 5y agoMy guess is that the problem isn't with this line per-se, but that some of those components in that string of dots are unions, that the program is doing one of those things with unions that have always officially been undefined behavior (so older standards aren't going to help) but which used to happen to work reliably, and that that's tripping up the modern compilers. I'd look at the types of hash_ptr, hash_ptr.parm, hash_ptr.parm.v, and hash_ptr.parm.v.p; I'd try building without optimizations (-O0) and see if that changes anything; and as others have said I'd try pulling it up in a debugger so I can poke things.
- UncleEntity 5y agoCompilers are pretty good at telling you what they’re unhappy about these days so you’re well on the track as opposed to chasing bugs in gdb. Usually when I get to the stage where whatever I’m working on is ready to build I pipe stderr to a file and just go down the list fixing all the little things until it works (or usually segfaults). I’ve successfully updated quite a few super old codebases to play around with by just fixing each compiler error until it works or I have to go hunting real bugs.