RISC OS C Programming FAQ

From RISC OS
Revision as of 11:37, 22 May 2006 by Caliston (talk | contribs) (Add question about GCC on RISC OS 3.1, ARM 2/3)
Jump to navigationJump to search

RISC OS C Frequently Asked Questions

As always, there are questions which are perennial, and usually have quite simple answers (to those who know them). And quite often, the solution is a FAQ.

Q. Can I ask you for help with my programming problem?

Only if it directly relates to content on this site - e.g., the tutorials - otherwise if it's RISC OS related, you should ask in one of the programming forums, such as comp.sys.acorn.programmer.

Q. Where can I find the latest version of GCC for RISC OS?

The latest release is available from the GCCSDK page. Experimental versions may also be available there.

Q. How do I call a SWI in C?

In the first instance, don't. Instead, you should use a library which provides an interface to the SWI - this will give you better type checking, and minimise any mistakes. OSLib provides such an interface to call most RISC OS SWIs.

If you still need to call a SWI, then you can use the _swix and _kernel_swi functions provided by SharedCLibrary and Unixlib. Alternatively, you may find it easier to use a SWI library such as DeskLib.

Q. Why are C++ programs with GCC so big?

Firstly, GCC programs by default link with UnixLib, which is statically linked to your program. There is a minimum of about 80k added to your code. Also, some types of C++ programming, especially use of templates, generates large amounts of output. Additionally, some types of template construct generate repeated code due to limitations of the AOF format. Finally, ensure you've got optimisation turned on with a -O flag.

Q. Can C++ programs with GCC link with the SharedCLibrary?

Yes, recent versions of GCC support linking C++ with the SharedCLibrary; this may be useful to reduce the size of your output.

Q. Why can't GCC/LCC create modules?

Recent versions of GCC and its toolchain have full module support.

Q. My module with floating point code crashes/aborts!?

Floating point instructions did not work correctly in modules until RISC OS 5 and RISC OS Select. It is possible to configure GCC to build with a software floating point library instead (the -msoft-float option), but this requires libgcc (a part of GCC) to be built with this option and so isn't available unless you rebuild GCC yourself.

Q. Where can I get GNU Make/other tools for RISC OS?

Make is available in the GCC distribution along with other tools including find, gzip, grep, etc.

Q. Is GCC/UnixLib 32-bit Ready?

All versions of GCC have been 32-bit compatible for a number of years. Producing 26-bit code is no longer supported.

Q. Will GCC/UnixLib build code for RISC OS 3.1, ARM2/3?

UnixLib has not been tested on RISC OS 3.1, and may well not work due to using long multiply instructions (not present until ARM7) and the runtime stack designed for later OS versions. Current versions of GCC output code in APCS-32 which should work on RISC OS 3.1 but for the fact that their code is intended for ARM6 and above. Option -mcpu=arm3 outputs ARM3 compatible code in APCS-26 mode, but this cannot be linked with APCS-32 Unixlib. Using -march=armv3 instead outputs ARM3 compatible code but in APCS-32.

So, in summary:

  • GCC 2.95.4 was the last release using 26 bit APCS-26. This is recommended if you are targeting RISC OS 3.1 alone.
  • For later versions of GCC use -march=armv3 and link with the SharedCLibrary (-mlibscl). This method is untested but the one most likely to work with later GCCs.

Q. Can GCC use Acorn's linker instead of Drlink?

Yes. In some circumstances it may be desirable to use this instead. In principle, Drlink should do everything that the Acorn linker does, but because of bugs or feature improvements, it may not in a released form.

It is possible to call link directly, but this is not recommend as it will not correctly set the options and libraries that GCC requires. Instead, set the variable:

 *set GCC$Linker link

Note that if you do find it neccessary to do this, the GCCSDK team would like to hear about it so Drlink can be fixed.