OSDK - missing definitions in macros.h

Questions, bug reports, features requests, ... about the Oric Software Development Kit. Please indicate clearly in the title the related element (OSDK for generic questions, PictConv, FilePack, XA, Euphoric, etc...) to make it easy to locate messages.

User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

OSDK - missing definitions in macros.h

Post by iss »

Hi all,
When I try to compile this code with OSDK:

Code: Select all

#define A      1
#define B      (1 << (A - 2))
#define C      (1 >> (A - 2))
void main(void)
{
  int x;
  x = A + B + C;
}
The build fails:

Code: Select all

 
LSHW_CCD(1,-1,tmp0)
obj/tests.o1:line 277: 06c2:Syntax error
 RSHW_CCD(1,-1,tmp1)
obj/tests.o1:line 285: 06c8:Syntax error
It's obvious that the above example isn't very correct (left/right shift 1 with negative number)
but the compiler generates relevant macro names 'LSHW_CCD' and 'RSHW_CCD' which are missing from file 'MACROS.H'

In 'MACROS.H' file I found defined:
#define LSHW_DCD(tmp1,cte2,tmp3)\
#define LSHW_CDD(cte1,tmp2,tmp3)\

But I don't know how the missing LSHW_CCD should look like : :?
Any ideas?
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug »

Are these operations generated only when providing negative shift values?
User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss »

Yes, only when providing negative shift values.
And probably the usage of '#define' is somehow involved too.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug »

iss wrote:And probably the usage of '#define' is somehow involved too.
I doubt that.
What the compiler gets has already been preprocessed, so what you actually compile is:

Code: Select all

void main(void)
{
  int x;
  x = 1 + (1 << (1 - 2)) + (1 >> (1 - 2));
}
User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss »

Indeed, I agree with your logic!
But... This WORKS just fine:

Code: Select all

static const A=1;
static int B;
static int C;

void main(void)
{
  int x;
  B =(1 << (A - 2));
  C =(1 >> (A - 2));
  x = A + B + C;
  printf("x=%d", x);
}
and this FAILS:

Code: Select all

#define A 1
static int B;
static int C;
void main(void)
{
  int x;
  B =(1 << (A - 2));
  C =(1 >> (A - 2));
  x = A + B + C;
  printf("x=%d", x);
}
[XA] obj/main.o -> tests
LSHW_CCD(1,-1,tmp0)
obj/tests.o1:line 277: 06c2:Syntax error
RSHW_CCD(1,-1,tmp0)
obj/tests.o1:line 283: 06cc:Syntax error
Break after 2 errors
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug »

Try your second example without the define, just using "1" instead of "A":

Code: Select all

static int B;
static int C;
void main(void)
{
  int x;
  B =(1 << (1 - 2));
  C =(1 >> (1 - 2));
  x = 1 + B + C;
  printf("x=%d", x);
}
That one should fail as well.

The problem is just the expressions "1<<(-1)" and "1>>(-1)" which resolve to something not supported.
Technically, I have no idea what the result should be, because it's just a logic error at the code level: Should a negative left shift be an actual right shift?
User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss »

I tested the code with some compilers and results are different depending on the particular compiler.
But this is expected when the code is not correct.
Else, having negative left shift to be right shift is really nice idea - I like this way of thinking ;).
Actually my point was only to mark that LCC can generate a macro name which is missing in "macro.h"
and it's interesting for me to know what *_CCD, *_DCD, etc. suffixes are.
If someday I have more free time probably will look at sources...
Thanks Dbug and cheers :).
User avatar
polluks
Pilot Officer
Posts: 76
Joined: Tue Jun 05, 2012 10:09 pm
Location: Germany
Contact:

Re: OSDK - missing definitions in macros.h

Post by polluks »

Negative integers on right-hand side is undefined behavior in the C language.
http://stackoverflow.com/questions/4945 ... hift-count
cc65 development
Oric Atmos + Cumulus
Acorn Electron
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug »

I guess, if these two "instructions" are generated only in the case of illegal/undefined conditions, we could just implement them as error messages from the assembler.
But ideally, we would like the compiler to do it, so we get the correct line number in the source file.
Post Reply