cc65 / c89 / c90 compiler support suggestions.
See original GitHub issueTo support c89 with try catch you could base your output off “setjmp” && “longjmp”.
#include <stdio.h>
#include <setjmp.h>
jmp_buf __threadExceptionBuff;
#define TRY switch(setjmp(__threadExceptionBuff)) { case 0: while(1) {
#define CATCH(x) break; case x:
#define FINALLY break; } default: {
#define TRY_END break; } }
#define THROW(x) longjmp(__threadExceptionBuff, x)
#define EXCEPTION (1)
#define NOT_IMPLEMENTED_EXCEPTION (2)
void Foo()
{
THROW(NOT_IMPLEMENTED_EXCEPTION);
}
void main()
{
TRY
{
printf("Start\n");
Foo();
printf("End\n");
}
CATCH (NOT_IMPLEMENTED_EXCEPTION)
{
printf("Catch Not Implemented Exception\n");
}
CATCH (EXCEPTION)
{
printf("Catch Exception\n");
}
FINALLY
{
printf("Finally\n");
}
To support c89 local variable scoping rules. You could define all of local variables that live on the stack at the top of each block. Example:
struct A
{
int x, y;
};
void Foo()
{
// all local stack objects within this scope get pre-defined up here at the top of the block
A a;
A a2;
int i;
// Now you can use them normally and this will compile in c89....
for (i = 0; i != 1; ++i)
{
// all local stack objects within this scope get pre-defined up here at the top of the block
A b;
float t;
// do stuff....
}
}
I use the c65 compiler to test out portability: https://github.com/cc65/cc65
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is it worth writing C89 compliant code? : r/C_Programming
MSVC has always been a C++ compiler that just happens to put the bare minimum effort into C support for the sake of...
Read more >cc65 Users Guide
cc65 is a C compiler for 6502 targets. It supports several 6502-based home computers such as the Commodore and Atari machines, but it...
Read more >Maybe yet another C Compiler for 6502 programming...
I'm in the process of developing a C-like compiler focused on generating optimized 8-bit code for the 6502 to use for developing projects ......
Read more >Headers are making my head hurt...
Not recommended! From the CC65 website: "Please note that the compiler does not support the C99 standard and never will. c99 mode is...
Read more >Compliling c programs to C89/C90 standard in VSC
I'm learning C90/90 in uni using MinGW compiler. Now I want to use VSC instead of CodeBlocks which my prof uses.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes the “GitHub topics”. Makes it easier for others to find your project 😃
Are you explaining it about the “GitHub topics?” I didn’t know it! I’ll set it.