egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
69 stars 17 forks source link

Use `if` instead of `do` for multicommand macros (possible fix to #528 -- STklos seems to only compile with `USE_COMPUTED_GOTO`) #561

Closed jpellegrini closed 1 year ago

jpellegrini commented 1 year ago

Hi @egallesio !

This seems to fix #528 ... I'm not sure it's the best way, but it was easy to implement, so here it is.

The commit message:

It is common practice to use

 #define SOME_MACRO do{ \
  ... \
  ... \
}while(0)

so that SOME_MACRO can be used inside ifs and other C commands.

However, this can lead to problems:

 #define NEXT continue
...
...
for(;;) {
...
 #define LOCK_AND_RESTART                 do{\
  if (!have_global_lock) {                   \
    ...                                      \
    NEXT;                                    \
  }                                          \
}while(0)
...
} /* for(;;) */

The NEXT expands into continue, which will break out of the do, and not continue the for loop as intended.

So we insteda use if(1){ ... }else{} for all multi-command macros.

jpellegrini commented 1 year ago

Hi @egallesio ! I'm closing this, since you have merged the other one! :)

egallesio commented 1 year ago

Oops didn't see that you had a PR with if/else.