MQX 3.5.1 little bug inside USB in host_debug.h

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MQX 3.5.1 little bug inside USB in host_debug.h

2,557件の閲覧回数
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 ; 

 



ラベル(1)
タグ(1)
0 件の賞賛
返信
3 返答(返信)

1,216件の閲覧回数
JuroV
NXP Employee
NXP Employee

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

0 件の賞賛
返信

1,216件の閲覧回数
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.

 

1,216件の閲覧回数
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 件の賞賛
返信