RISC OS Open
Safeguarding the past, present and future of RISC OS for everyone
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account
Forums → Community Support →

DDF28a a = b - (c * d)

Subscribe to DDF28a a = b - (c * d) 4 posts, 3 voices

 
Nov 3, 2017 3:33pm
Avatar David Pitt (3386) 1241 posts

There may be a further issue with DDE28a, cc 5.75.

A recent compiler change is to do with handling integer expressions of the form :-

  a = b - (c * d)

The following does not perform as expected when compiled with cc 5.75.

#include <stdio.h>

int main(void)
{
int a=0, b=10,c=4,d=2;
printf("Hello DDE28a\n");
a = b - (c * d);
printf("%d\n",a);
if (a == 0) printf("Oh crap\n");
return(0);
}

The compilation is done with either !CC or Makefile, with either a DDE28a or Builder environments.

It is OK with DDE27 and gcc.

C and I don’t belong in the same sentence, so I thought I would ask.

What does the team think?

Edit, updated examples http://pittdj.co.uk/rool/test.zip

 
Nov 3, 2017 4:48pm
Avatar Sprow (202) 999 posts

I don’t think that’s testing what you think its testing, since the values of b/c/d are known at compile time, the output code contains neither an MLS nor a MUL/SUB. If you force one of the variables to do some work to get it then the answer is right:

int anumber(void) { return 4; }
int main(void)
{
int a=0, b=10,c=anumber(),d=2;
printf("Hello DDE28a\n");
a = b - (c * d);
printf("%d\n",a);
}

That said, it should get it right so it’s worth reporting to ROOL, but in practice it’s unlikely to be a problem. You’ll note the change log includes a fix for compile time evaluation of modulo which hadn’t worked for years and nobody noticed (I found that one during some Econet testing).

 
Nov 3, 2017 5:45pm
Avatar David Pitt (3386) 1241 posts

That said, it should get it right so it’s worth reporting to ROOL

The ReadMe in DDE28 has the forum as the point of contact for ROOL support.

I have tidied up my example zip and removed inappropriate MLS references.

For source and executables see http://pittdj.co.uk/rool/test.zip

Further testing shows the issue is not present in the first issue of DDE28, cc 5.74.

 
Nov 3, 2017 10:04pm
Avatar Rick Murray (539) 11630 posts

You’ll note the change log

Which change log?

includes a fix for compile time evaluation of modulo which hadn’t worked for years and nobody noticed (I found that one during some Econet testing).

That’s the ‘%’ operator isn’t it? I might have run into this building some #defines a few years ago. The results were not as expected. Rather than look into things, I just did the maths in BASIC and replaced the calculations with hardcoded values. It was something to do with seconds in day, hour, minute, etc…

Reply

To post replies, please first log in.

Forums → Community Support →

Search forums

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Description

Community-provided support for all users of RISC OS.

Voices

  • David Pitt (3386)
  • Sprow (202)
  • Rick Murray (539)

Options

  • Forums
  • Login
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Beast theme is based on Beast's default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Beast © 2006 Josh Goebel and Rick Olson
This site runs on Rails

Hosted by Arachsys