mirror of
https://github.com/cc65/cc65.git
synced 2025-01-29 21:31:53 +00:00
commit
bdb01212c2
73
test/val/add3a.c
Executable file
73
test/val/add3a.c
Executable file
@ -0,0 +1,73 @@
|
||||
|
||||
/*
|
||||
!!DESCRIPTION!! Addition tests - mostly int's
|
||||
!!ORIGIN!! SDCC regression tests
|
||||
!!LICENCE!! GPL, read COPYING.GPL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned int failures = 0;
|
||||
|
||||
/*
|
||||
this test assumes:
|
||||
sizeof(long) == 4
|
||||
|
||||
CAUTION: the wraparound behaviour is actually undefined, to get the "expected"
|
||||
behaviour with GCC, use -fwrapv or -fno-strict-overflow
|
||||
|
||||
see: https://gcc.gnu.org/wiki/FAQ#signed_overflow
|
||||
*/
|
||||
|
||||
#ifdef REFERENCE
|
||||
|
||||
/*
|
||||
make sure the reference output uses types with
|
||||
proper size
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t long0 = 0;
|
||||
|
||||
#else
|
||||
|
||||
long long0 = 0;
|
||||
|
||||
#endif
|
||||
|
||||
void print(void)
|
||||
{
|
||||
#if defined(REFERENCE) && defined(REFCC_SIZEOF_LONG_64BIT)
|
||||
printf("long0: %d\n", long0);
|
||||
#else
|
||||
printf("long0: %ld\n", long0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long0 = 0x7f000000L;
|
||||
/* wrap around zero */
|
||||
print();
|
||||
long0 = long0 + 0x2000000L;
|
||||
if(long0 != -0x7f000000L) {
|
||||
printf("failed!\n");
|
||||
failures++;
|
||||
}
|
||||
print();
|
||||
|
||||
long0 = 0x7f000000L;
|
||||
/* wrap around zero */
|
||||
print();
|
||||
long0 = long0 + 0x2000000L;
|
||||
print();
|
||||
if(long0 != -0x7f000000L) {
|
||||
printf("failed!\n");
|
||||
failures++;
|
||||
}
|
||||
print();
|
||||
|
||||
return failures;
|
||||
}
|
49
test/val/casttochar.c
Executable file
49
test/val/casttochar.c
Executable file
@ -0,0 +1,49 @@
|
||||
|
||||
/*
|
||||
!!DESCRIPTION!! Cast to char
|
||||
!!ORIGIN!! Piotr Fusik
|
||||
!!LICENCE!! PD
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned int failures = 0;
|
||||
|
||||
int f1(int i, int j) {
|
||||
return (signed char) (i + 1) == j;
|
||||
}
|
||||
|
||||
int f2(int i, int j) {
|
||||
return (unsigned char) (i + 1) == j;
|
||||
}
|
||||
|
||||
int f3(int i, int j) {
|
||||
return (char) (i + 1) == j;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("f1: got :%04x ", f1(0x1234, 0x35));
|
||||
if(f1(0x1234, 0x35) == 0) {
|
||||
printf("- failed");
|
||||
failures++;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("f2: got :%04x ", f2(0x1234, 0x35));
|
||||
if(f2(0x1234, 0x35) == 0) {
|
||||
printf("- failed");
|
||||
failures++;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("f3: got :%04x ", f3(0x1234, 0x35));
|
||||
if(f3(0x1234, 0x35) == 0) {
|
||||
printf("- failed");
|
||||
failures++;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return failures;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user