MQX 3.5.1 little bug inside USB in host_debug.h

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX 3.5.1 little bug inside USB in host_debug.h

1,839 Views
admin
Specialist II

When I enable this define for the debug


#define _DEBUG_INFO_TRACE_LEVEL_
#define _HOST_DEBUG_


there is a compilation problem,


#define DEBUG_LOG_TRACE(x) printf("\n%s",x);

 

the ; is an error because in the rest of the code when used DEBUG_LOG_TRACE there is always

...example code in host_main.c...

 

DEBUG_LOG_TRACE("_usb_host_init host state malloc failure");  

with ; 

 



Labels (1)
Tags (1)
0 Kudos
3 Replies

498 Views
JuroV
NXP Employee
NXP Employee

Hello, it's not a bug, but for cleaner code it couldnt be there, I agree.

0 Kudos

498 Views
CompilerGuru
NXP Employee
NXP Employee

It's not a bug per se unless the "DEBUG_LOG_TRACE("_usb_host_init host state malloc failure");" is used

inside of an if (or else, for, while,...) without braces.

I never use if's without braces so I dont have this issue thoug :smileyhappy:.


The DEBUG_LOG_TRACE could be improved by surrounding it with a do { .... } while (0) construct

(some hide that behind another set of macros). Also I would suggest to use braces around all macro arguments whenever possible, and I would not use printf but calls to fputc('\n', stdout); fputs((x), stdout); to avoid the missing argument check due to the open argument signature of printf.

Maybe using stderr instead of stdout might be considered as well.

 

498 Views
JuroV
NXP Employee
NXP Employee

I personally think that printf should not be used in conditional bracket as the return value from printf is not defined in MQX. You can use DEBUG_LOG_TRACE inside { } parentheses. DEBUG_LOG_TRACE is just a macro to put down result of operation in debug state- if you don't like it, you can redefine it. For nowadays purpose, it is sufficient.

0 Kudos