◄ Back to index

# Frequently Asked Questions

# Common issues

## (on-calc) I keep getting errors such as "`not enough memory to compile function abc`"

This could be because you do not have enough free RAM (more than 100kb is recommended), but if you have enough RAM it is probably because the function abc is too large to fit in the memory of the calculator. You will need to split into smaller functions to avoid the error.

Another reason could be that you have a `#define` with a large body, or a very large number of global declarations. This shouldn't be a problem for most programs, but if you think you are in this case, you can try to solve it with `#undef` or by creating a precompiled header.

# Differences between GTC and TIGCC

## How can I port my program from TIGCC to GTC?

It all depends on what features your program uses. Here is a list of porting issues:

- `long long` support: GTC does not support them, if you use them you will have to rewrite your code to use two `long`s instead. In many cases it's very easy to port.
- `asm()` vs `asm{}`: the assembly syntax is different between GTC and TIGCC. However if you are familiar with a68k you will be able to use GTC's syntax in no time.
- `float`/`double` support: currently, GTC does not support floats. If your program uses floats, then unless you think you can get rid of them (e.g. if you are only using them for sines and cosines, you can use a pre-computed table instead), you're basically stuck and should definitely continue using TIGCC (unless you're willing to go down to the assembly level). Sorry.

Additionally, you may run into these little behaviour differences:

- Cast constructors: currently, the following code

      int *f(int *dest,int x) {
          memcpy(dest,(int[4]){x,x+1,x+2},8);
          return dest;
      }

  is not accepted by GTC because the array constructed is not constant (`x` is not known at compile time). But you can rewrite it to use a temporary array instead:

      int *f(int *dest,int x) {
          int temp[4] = {x,x+1,x+2};
          memcpy(dest,temp,8);
          return dest;
      }

- Calling convention: by default, GTC uses the `regparm(2,1)` convention, while TIGCC uses the `stkparm` convention. This is only a problem if you have written assembly functions yourself; in this case, you have to specify the calling convention you use in the prototype, e.g.:

      asm {
      upper_8_bits:
          move.b 4(a7),d0
          rts
      };
      char upper_8_bits(long x);

  would become

      asm {
      upper_8_bits:
          move.b 4(a7),d0
          rts
      };
      char upper_8_bits(long x) __attribute__((stkparm));

This list may not be exhaustive, but I will be happy to hear about any problems you might have that are not mentioned in this list.

## How can I make sure my GTC program can be compiled with TIGCC too?

You should not have much trouble compiling GTC programs with TIGCC as GTC was designed to introduce as few incompatibilities as possible. However, if you use low-level features like assembly you might run into some problems:

- See if your program uses GTC-specific extensions. For example, if you really need to use a short bit of assembly you can use conditional compilation to turn a GTC-only program like this one:

      asm {
      turn_calculator_off:
          trap #4
          rts
      };

  into this more portable program:

      #ifdef __GTC__
      /* assembly code using GTC's asm{} syntax */
      asm {
      turn_calculator_off:
          trap #4
          rts
      };
      #else
      /* assembly code using TIGCC's asm() syntax */
      asm("
      turn_calculator_off:
          trap #4
          rts
      ");
      #endif

- The default calling convention is different, so if you define your own assembly functions and call them from C code make sure their prototypes are properly specified with `regparm`.