What is the input to obtain Z_S_SEMPTY_CSE_0001

Hi:

Pls help me!

I use ncs v2.6.1.

C:\ncs\v2.6.1\zephyr\include\zephyr\sys\util_internal.h

When I check #define Z_IS_EMPTY_(...)  No matter what I input, I can't get Z_S_SEMPTY_CSE_0001.

It is a check EMPTY.

if  #define XX 1 use IS_EMPTY(XX).

#define IS_EMPTY(...) Z_IS_EMPTY_(__VA_ARGS__)

#define Z_TRIGGER_PARENTHESIS_(...) ,

#define Z_IS_EMPTY_(...) \

    Z_IS_EMPTY__( \

        Z_HAS_COMMA(__VA_ARGS__), \

        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ __VA_ARGS__), \

        Z_HAS_COMMA(__VA_ARGS__ (/*empty*/)), \

        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ __VA_ARGS__ (/*empty*/)))

 /* analysis

    Z_IS_EMPTY__( \

    Z_HAS_COMMA(XX), \

    Z_HAS_COMMA(, XX), \

    Z_HAS_COMMA(XX() ), \

    Z_HAS_COMMA(, XX () )  \

->

   0,\

   1,\

   0,\

   1,\

*/

#define Z_IS_EMPTY__(_0, _1, _2, _3) \

Z_HAS_COMMA(Z_CAT5(Z_IS_EMPTY_CASE_, _0, _1, _2, _3))

/* analysis

Z_HAS_COMMA(Z_CAT5(Z_IS_EMPTY_CASE_, 0, 1, 0, 1))

->

Z_IS_EMPTY_CASE_0101

not Z_IS_EMPTY_CASE_0001

So it should return 0,But we know it has already been defined, it should return 1.

*/

#define Z_IS_EMPTY_CASE_0001 ,

 

#define Z_HAS_COMMA(...) \

    NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, \

     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \

     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \

     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)

 

#define NUM_VA_ARGS_LESS_1_IMPL(                \

    _ignored,                       \

    _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,        \

    _11, _12, _13, _14, _15, _16, _17, _18, _19, _20,   \

    _21, _22, _23, _24, _25, _26, _27, _28, _29, _30,   \

    _31, _32, _33, _34, _35, _36, _37, _38, _39, _40,   \

    _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,   \

    _51, _52, _53, _54, _55, _56, _57, _58, _59, _60,   \

    _61, _62, N, ...) N

Parents
  • Hello,

    I don't understand much of what you are testing here, but I suspect you started in the wrong end. My guess is that there is something wrong with one of your log messages, that causes the application not to build. So either one of your calls to printk() or one of your calls to LOG_INF(), LOG_ERR(), LOG_WRN() or something has a syntax error. Those tend to result in weird compiler errors that are difficult to understand. So is this the case? You got some compiler error? 

    If so, try looking at the top of the error in the build log. If you are building in VS Code, then that may be difficult, because it is cropped, but if you try to build in a command line, you should be able to see it all. Alternatively, if you recently added some logs, try commenting them out, and add them back one by one to figure out which one that has the error. 

    If that is not what you are asking, perhaps some more context can help me understand what you are trying to figure out.

    Best regards,

    Edvin

  • Hi

    Sorry,I didn't describe my problem well.

    I am analyzing the IS_EMPTY macro and I do not understand it.

    Example 1, I input a parameter

    #define EMPTY
    input  IS_EMPTY(EMPTY)  Based on the results of my analysis:
    Z_IS_EMPTY_CASE_0101
     
    Example 2
    #undef  UNDEFINED
    input  IS_EMPTY(EMPTY)  Based on the results of my analysis:
    Z_IS_EMPTY_CASE_0101
    So it cannot check EMPTY.
    My analysis process:
    IS_EMPTY(EMPTY)
    
    IS_EMPTY(...) -> Z_IS_EMPTY_(__VA_ARGS__)
    
    Z_IS_EMPTY_(EMPTY) -> Z_IS_EMPTY__( \
        Z_HAS_COMMA(EMPTY), \
        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ EMPTY), \
        Z_HAS_COMMA(EMPTY (/*empty*/)), \
        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ EMPTY (/*empty*/)))
    
    Z_HAS_COMMA(EMPTY)  --> result 0
    Z_HAS_COMMA(,EMPTY)  --> result 1
    Z_HAS_COMMA(EMPTY(/*empty*/))  --> result 0
    Z_HAS_COMMA(,EMPTY(/*empty*/))  --> result 1
    
    so result
    Z_IS_EMPTY_CASE_0101
    When I entered #undef  UNDEFINED, I analyzed it the same way, and the result was the same.
Reply
  • Hi

    Sorry,I didn't describe my problem well.

    I am analyzing the IS_EMPTY macro and I do not understand it.

    Example 1, I input a parameter

    #define EMPTY
    input  IS_EMPTY(EMPTY)  Based on the results of my analysis:
    Z_IS_EMPTY_CASE_0101
     
    Example 2
    #undef  UNDEFINED
    input  IS_EMPTY(EMPTY)  Based on the results of my analysis:
    Z_IS_EMPTY_CASE_0101
    So it cannot check EMPTY.
    My analysis process:
    IS_EMPTY(EMPTY)
    
    IS_EMPTY(...) -> Z_IS_EMPTY_(__VA_ARGS__)
    
    Z_IS_EMPTY_(EMPTY) -> Z_IS_EMPTY__( \
        Z_HAS_COMMA(EMPTY), \
        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ EMPTY), \
        Z_HAS_COMMA(EMPTY (/*empty*/)), \
        Z_HAS_COMMA(Z_TRIGGER_PARENTHESIS_ EMPTY (/*empty*/)))
    
    Z_HAS_COMMA(EMPTY)  --> result 0
    Z_HAS_COMMA(,EMPTY)  --> result 1
    Z_HAS_COMMA(EMPTY(/*empty*/))  --> result 0
    Z_HAS_COMMA(,EMPTY(/*empty*/))  --> result 1
    
    so result
    Z_IS_EMPTY_CASE_0101
    When I entered #undef  UNDEFINED, I analyzed it the same way, and the result was the same.
Children
  • Hello,

    I have never looked this deep into these zephyr macros. Do you strictly need to use these? Are you writing some driver for Zephyr that needs to utilize this? Or could you create your own macros for what you want to achieve? I still don't understand what you mean by Z_IS_EMPTY_CASE_0101? Is this defined somewhere? Because searching in my NCS folder, I can't find it. Perhaps it is different on the NCS version that I am currently using.

    I would think it was natural to use something like:

    #define IS_EMPTY(expression) (!defined(expression))
    
    #define IS_ENABLED(expression) ((defined(expression) &&(expression) ? 1 : 0)

    Or something like that.

    Have you tried reaching out for Zephyr with this question? I imagine they know these macros on a more detailed level than we do. 

    Best regards,

    Edvin

Related