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.

Post Reply
User avatar
iss
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

OSDK - missing definitions in macros.h

Post by iss » Tue Nov 11, 2014 11:05 pm

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: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug » Fri Nov 14, 2014 9:55 pm

Are these operations generated only when providing negative shift values?

User avatar
iss
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss » Fri Nov 14, 2014 10:00 pm

Yes, only when providing negative shift values.
And probably the usage of '#define' is somehow involved too.

User avatar
Dbug
Site Admin
Posts: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug » Fri Nov 14, 2014 10:15 pm

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
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss » Fri Nov 14, 2014 10:47 pm

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: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug » Fri Nov 14, 2014 11:14 pm

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
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: OSDK - missing definitions in macros.h

Post by iss » Sat Nov 15, 2014 12:14 pm

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
Officer Cadet
Posts: 56
Joined: Tue Jun 05, 2012 10:09 pm
Location: Germany
Contact:

Re: OSDK - missing definitions in macros.h

Post by polluks » Sat Nov 15, 2014 11:12 pm

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: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK - missing definitions in macros.h

Post by Dbug » Sun Nov 16, 2014 11:51 am

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

Who is online

Users browsing this forum: No registered users and 5 guests