Skip to content

Commit

Permalink
Investigating bitness issue on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Sep 21, 2024
1 parent 8f615f7 commit a692966
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions source/toy_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//TOY_API is platform-dependant, and marks publicly usable API functions
#if defined(__linux__)
#define TOY_API extern
#elif defined(_MSC_VER)
#elif defined(_WIN32) || defined(_WIN64)
#ifndef TOY_EXPORT
#define TOY_API __declspec(dllimport)
#else
Expand All @@ -28,7 +28,7 @@
#else
#define TOY_BITNESS 32
#endif
#elif defined(_MSC_VER)
#elif defined(_WIN32) || defined(_WIN64)
#if defined(_WIN64)
#define TOY_BITNESS 64
#else
Expand Down
37 changes: 20 additions & 17 deletions tests/cases/test_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdio.h>

int test_sizeof_ast_32bit() {
int test_sizeof_ast_64bit() {
#define TEST_SIZEOF(type, size) \
if (sizeof(type) != size) { \
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \
Expand All @@ -15,21 +15,22 @@ int test_sizeof_ast_32bit() {

//run for each type
TEST_SIZEOF(Toy_AstType, 4);
TEST_SIZEOF(Toy_AstBlock, 16);
TEST_SIZEOF(Toy_AstBlock, 32);
TEST_SIZEOF(Toy_AstValue, 12);
TEST_SIZEOF(Toy_AstUnary, 12);
TEST_SIZEOF(Toy_AstBinary, 16);
TEST_SIZEOF(Toy_AstGroup, 8);
TEST_SIZEOF(Toy_AstUnary, 16);
TEST_SIZEOF(Toy_AstBinary, 24);
TEST_SIZEOF(Toy_AstGroup, 16);
TEST_SIZEOF(Toy_AstPass, 4);
TEST_SIZEOF(Toy_AstError, 4);
TEST_SIZEOF(Toy_Ast, 16);
TEST_SIZEOF(Toy_AstEnd, 4);
TEST_SIZEOF(Toy_Ast, 32);

#undef TEST_SIZEOF

return -err;
}

int test_sizeof_ast_64bit() {
int test_sizeof_ast_32bit() {
#define TEST_SIZEOF(type, size) \
if (sizeof(type) != size) { \
fprintf(stderr, TOY_CC_ERROR "ERROR: sizeof(" #type ") is %d, expected %d\n" TOY_CC_RESET, (int)sizeof(type), size); \
Expand All @@ -41,14 +42,15 @@ int test_sizeof_ast_64bit() {

//run for each type
TEST_SIZEOF(Toy_AstType, 4);
TEST_SIZEOF(Toy_AstBlock, 32);
TEST_SIZEOF(Toy_AstBlock, 16);
TEST_SIZEOF(Toy_AstValue, 12);
TEST_SIZEOF(Toy_AstUnary, 16);
TEST_SIZEOF(Toy_AstBinary, 24);
TEST_SIZEOF(Toy_AstGroup, 16);
TEST_SIZEOF(Toy_AstUnary, 12);
TEST_SIZEOF(Toy_AstBinary, 16);
TEST_SIZEOF(Toy_AstGroup, 8);
TEST_SIZEOF(Toy_AstPass, 4);
TEST_SIZEOF(Toy_AstError, 4);
TEST_SIZEOF(Toy_Ast, 32);
TEST_SIZEOF(Toy_AstEnd, 4);
TEST_SIZEOF(Toy_Ast, 16);

#undef TEST_SIZEOF

Expand Down Expand Up @@ -194,22 +196,23 @@ int main() {
//run each test set, returning the total errors given
int total = 0, res = 0;

#if TOY_BITNESS == 32
res = test_sizeof_ast_32bit();

#if TOY_BITNESS == 64
res = test_sizeof_ast_64bit();
total += res;

if (res == 0) {
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
}
#elif TOY_BITNESS == 64
res = test_sizeof_ast_64bit();
#elif TOY_BITNESS == 32
res = test_sizeof_ast_32bit();
total += res;

if (res == 0) {
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
}
#else
fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_*bit(); Can't determine the 'bitness' of this platform\n" TOY_CC_RESET);
fprintf(stderr, TOY_CC_WARN "WARNING: Skipping test_sizeof_ast_*bit(); Can't determine the 'bitness' of this platform (seems to be %d)\n" TOY_CC_RESET, TOY_BITNESS);
#endif

{
Expand Down

0 comments on commit a692966

Please sign in to comment.