question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cc65 / c89 / c90 compiler support suggestions.

See original GitHub issue

To 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:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zezba9000commented, Nov 16, 2018

Yes the “GitHub topics”. Makes it easier for others to find your project 😃

0reactions
kekyocommented, Nov 16, 2018

Are you explaining it about the “GitHub topics?” I didn’t know it! I’ll set it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found