rokath / trice

🟢 super fast 🚀 and tiny 🐥 embedded device 𝘾 printf-like trace ✍ code, works also inside ⚡ interrupts ⚡ and real-time PC 💻 logging (trace ID visualization 👀)
MIT License
517 stars 46 forks source link

Fixes/lib (warnings compilation) #495

Closed Sazerac4 closed 2 months ago

Sazerac4 commented 2 months ago

Question:

Sazerac4 commented 2 months ago
rokath commented 2 months ago

Question: trice.c and trice.h files are now filtered from formatting. how formatting theses files are problematic ?

The mixed indent of macros and code is manually adapted. To not spoil the code with // clang-format off/on I excluded them for now to get automatic formatted, especially in the assumption, that this code will not see much changes.

I am not sure about the best way to handle that. Any proposals?

Edit: Maybe reordering the code that way, that only one code segment needs to be excluded from auto formatting.

Question: What is the purpose to use TRICE_INLINE instead of static inline. Some compilers got better attributes ?

If I remember right, I have seen C compilers with some weird function inline syntax. To handle such cases, the user can define the TRICE_INLINE macro accordingly.

Sazerac4 commented 2 months ago

I am not sure about the best way to handle that. Any proposals?

The problem is mixing preprocessor directives indenting with statements (if, for, switch, ...) indenting that might yield very misleading looking code when preprocessor is heavy used with code. example:

void foo(void) {
#if TEST1 == 0
    #if TEST2 == 0
        if (true) {  // This if is on the wrong indentation
    #endif
#endif
        for (int i = 0; i < 10; ++i) {
            // do something
        }
#if TEST1 == 0
    #if TEST2 == 0
        }  // This brace is on the wrong indentation
    #endif
#endif
}

I think we can reverse the logic, set IndentPPDirectives: None and add manual indentation when it is pertinent with clang-format off. Edit: It might be worth it. Most styles do not indent directives.

Edit: Maybe reordering the code that way, that only one code segment needs to be excluded from auto formatting.

I think you shouldn't code based on formatter (most of the time). We add unnecessary complexity when programming

rokath commented 2 months ago

Maybe we keep the trice8|16|32|64.c|h files inside .clang-format-ignore. These files would loose readability for my taste when re-formatted with IndentPPDirectives: None. But I have no strong opinion on this because they then formatted differently to trice.c|h. On trice.c|h I agree to drop the pre-processor macros indent. Edit: https://stackoverflow.com/questions/2975330/how-do-you-indent-preprocessor-statements