To avoid the build error "assignment within conditional expression" on VS

20 views
Skip to first unread message

Abner Chang

unread,
Jan 28, 2021, 9:23:22 AM1/28/21
to Jansson users

Hi all,

Some macros defined in jansson.h causes build error "assignment within conditional expression" on Visual Studio.

In order to not suppressing this error by using build option, how do you think to revise those macros a little bit like below?

Thanks

Abner

 

For example, revise below macro...

#define json_object_foreach(object, key, value)                                          \

     for (key = json_object_iter_key(json_object_iter(object));                           \

          key && (value = json_object_iter_value(json_object_key_to_iter(key)));          \

          key = json_object_iter_key(                                                     \

           json_object_iter_next(object,

          json_object_key_to_iter(key))))


 to,


#define json_object_foreach(object, key, value)                                          \

  for (key = json_object_iter_key(json_object_iter(object));                           \

       key;                                                                            \

       key = json_object_iter_key(                                                     \

            json_object_iter_next(object, json_object_key_to_iter(key)))) {            \

    value = json_object_iter_value(json_object_key_to_iter(key));                      \

    if (!value)                                                                        \

      break;                                                                           \

  }

Reply all
Reply to author
Forward
0 new messages