|
Question about replacing macros, static analysis tools hate (most of) them for good reason, but I'm unsure of what the best replacement is. Define a bunch of static inline functions for all required types, possibly with a macro'd _generic access, or a single templated version? Does it even matter?
|
# ¿ Aug 13, 2021 06:51 |
|
|
# ¿ May 21, 2024 00:09 |
|
Xarn posted:What kind of macros? What are they doing? Mostly basic stuff, min, max, abs, squares, cubes, root sum squares. Things that could be and should be done in real functions, but I'm mostly curious if there's a performance cost of switching them to templates.
|
# ¿ Aug 13, 2021 18:14 |
|
Foxfire_ posted:Doing something like lol wait is this not actually legal/well defined? our I/O code does this all over the place
|
# ¿ Sep 3, 2021 20:57 |
|
Foxfire_ posted:Yep, that's undefined behavior. Very interesting. I mean we do know it works, but no wonder the static analysis tools we recently implemented is so grumpy about it
|
# ¿ Sep 3, 2021 23:29 |
|
Okay so going back to the question of pulling data from a char buffer, what's the best way to actually handle something like this?code:
Currently this is actually handled in the code by declaring DataStruct with a bunch of char arrays instead of the full types, and then just casting it into the full type when required, as below (with simplified operations of course, these do need to be accessed separately): code:
The options as I see it are:
Is there a serious argument to made for one approach over the other?
|
# ¿ Sep 8, 2021 00:02 |
|
Very helpful, thanks for the input all!
|
# ¿ Sep 8, 2021 20:36 |
|
well it's late and I've been drinking, but your voidbutt is a pointer to a char pointer. Just dereference with char* pcGoodPointer = *(char**)voidbutt E: oh right you have to cast it first, can't dereference void directly. E2: Or just dereference twice? char** ppcFoo = voidbutt; printf("\nfirst char in string: %c", **ppcFoo); PittTheElder fucked around with this message at 04:39 on Sep 24, 2021 |
# ¿ Sep 24, 2021 04:20 |
|
|
# ¿ May 21, 2024 00:09 |
|
Strong Sauce posted:Thanks everyone for your sympathetic words. I kinda avoided this thread today because I was pretty exhausted from dealing with C++ at work that I wrote that out of frustration and didn't want to deal with anything C++ today. Just get a job doing embedded systems development with a company like mine who still uses C++99, we don't have to deal with any of that poo poo
|
# ¿ Feb 19, 2024 18:41 |