kayws426 / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

macro unexpected behavior #152

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

#include <stdio.h>

#define F_SELF_PLUS(a,b)    ( a += b )

int main()
{
  int ret = 0;
  F_SELF_PLUS(ret,3);
  //ret must be 3 at this point
  printf("ret = %d\n",ret);

  printf("----END----\n");
  return 0;
}

What is the expected output? What do you see instead?
basically it looks like that macros do not update the variables 

Example:
#define F_SELF_PLUS(a,b)    ( a += b )

  int ret = 0;
  F_SELF_PLUS(ret,3);
  //ret must be 3 at this point
  printf("ret = %d\n",ret);

Also there are issues with this kind of macro:

#define F_BIT_to_MASK(c)     ( 1 << c )
#define F_SET_BIT(a,b)       ( a |= (1 << b) )
#define F_RESET_BIT(a,b)     ( a &= (~(1 << b) ) )
#define F_SET_BIT2(a,b)      ( a |= F_BIT_to_MASK(b) )
#define F_RESET_BIT2(a,b)    ( a &= (~(F_BIT_to_MASK(b)) ) )

F_SET_BIT2 gives unexpected error.

Original issue reported on code.google.com by ozlbi...@gmail.com on 1 Feb 2012 at 6:16

GoogleCodeExporter commented 9 years ago
Macros in picoc are limited by design. It's a small language and only aims to 
do most, but not all of the ISO C standard.

Using macros in this way is unfortunately not supported by picoc.

Original comment by zik.sale...@gmail.com on 1 Mar 2014 at 4:30