1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-31 20:06:11 +00:00

sample program that demonstrates how to compare the value of __CC65__ for

any version of the compiler
This commit is contained in:
mrdudz 2022-05-10 01:16:19 +02:00
parent 1b73ffb8ae
commit 8062f8d029
2 changed files with 59 additions and 0 deletions

View File

@ -161,6 +161,7 @@ DIRLIST = tutorial geos atari2600 atari5200 apple2 gamate lynx supervision sym1
EXELIST_apple2 = \
ascii \
checkversion \
diodemo \
enumdevdir \
gunzip65 \
@ -177,6 +178,7 @@ EXELIST_apple2enh = $(EXELIST_apple2)
EXELIST_atari = \
ascii \
checkversion \
gunzip65 \
hello \
mandelbrot \
@ -197,6 +199,7 @@ EXELIST_atari5200 = \
EXELIST_atmos = \
ascii \
checkversion \
hello \
mandelbrot \
sieve \
@ -207,6 +210,7 @@ EXELIST_bbc = \
EXELIST_c64 = \
ascii \
checkversion \
enumdevdir \
gunzip65 \
hello \
@ -220,6 +224,7 @@ EXELIST_c64 = \
EXELIST_c128 = \
ascii \
checkversion \
enumdevdir \
gunzip65 \
hello \
@ -231,12 +236,14 @@ EXELIST_c128 = \
EXELIST_c16 = \
ascii \
checkversion \
enumdevdir \
tinyshell \
hello
EXELIST_cbm510 = \
ascii \
checkversion \
gunzip65 \
hello \
mousedemo \
@ -245,6 +252,7 @@ EXELIST_cbm510 = \
EXELIST_cbm610 = \
ascii \
checkversion \
gunzip65 \
hello \
tinyshell \
@ -252,10 +260,12 @@ EXELIST_cbm610 = \
EXELIST_creativision = \
ascii \
checkversion \
hello
EXELIST_cx16 = \
ascii \
checkversion \
enumdevdir \
gunzip65 \
hello \
@ -266,10 +276,12 @@ EXELIST_cx16 = \
tgidemo
EXELIST_gamate = \
checkversion \
hello
EXELIST_geos-cbm = \
ascii \
checkversion \
diodemo
EXELIST_geos-apple = \
@ -282,16 +294,19 @@ EXELIST_lynx = \
notavailable
EXELIST_nes = \
checkversion \
hello
EXELIST_osic1p = \
notavailable
EXELIST_pce = \
checkversion \
hello
EXELIST_pet = \
ascii \
checkversion \
enumdevdir \
hello \
tinyshell \
@ -299,6 +314,7 @@ EXELIST_pet = \
EXELIST_plus4 = \
ascii \
checkversion \
enumdevdir \
gunzip65 \
hello \
@ -306,6 +322,7 @@ EXELIST_plus4 = \
sieve
EXELIST_sim6502 = \
checkversion \
gunzip65
EXELIST_sim65c02 = $(EXELIST_sim6502)
@ -318,6 +335,7 @@ EXELIST_sym1 = \
EXELIST_telestrat = \
ascii \
checkversion \
gunzip65 \
hello \
mandelbrot \
@ -326,6 +344,7 @@ EXELIST_telestrat = \
EXELIST_vic20 = \
ascii \
checkversion \
enumdevdir \
hello \
mandelbrot \

40
samples/checkversion.c Normal file
View File

@ -0,0 +1,40 @@
/* Until 2.19 the __CC65__ macro was defined as (VER_MAJOR * 0x100) + (VER_MINOR * 0x10),
* which caused it to contain broken values in compiler releases 2.16 to 2.19. The
* macro was fixed some time after 2.19 to (VER_MAJOR * 0x100) + VER_MINOR.
*
* The following strategy can be used to still compare for less or greater versions,
* should this really be necessary or wanted - it is not recommended afterall.
*/
#include <stdio.h>
#include <stdlib.h>
#if ((__CC65__ & 0xff00) > 3) || ((__CC65__ & 0x000f) > 0)
/* compiler version is 2.19-git or higher */
# define VER_MAJOR ((__CC65__ >> 8) & 0xff)
# define VER_MINOR (__CC65__ & 0xff)
#elif ((__CC65__ & 0xff00) == 3)
/* broken values in version 2.16 - 2.19-git before the bug was fixed */
# define VER_MAJOR 2
# define VER_MINOR (((__CC65__ >> 4) & 0x0f) + 16)
#else
/* values before 2.16 */
# define VER_MAJOR ((__CC65__ >> 8) & 0xff)
# define VER_MINOR ((__CC65__ >> 4) & 0x0f)
#endif
/* define a new value that will work for comparing all versions */
#define VERSION ((VER_MAJOR << 8) + VER_MINOR)
int main(void)
{
printf("__CC65__ defined as %04x\n", __CC65__);
printf("compiler version is %u.%u\n", VER_MAJOR, VER_MINOR);
if (__CC65__ == VERSION) {
printf("__CC65__ is defined correctly as (VER_MAJOR * 0x100) + VER_MINOR\n");
return EXIT_SUCCESS;
}
printf("__CC65__ is incorrectly defined as (VER_MAJOR * 0x100) + (VER_MINOR * 0x10)\n");
return EXIT_FAILURE;
}