tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Two compilers at once


From: Karl Yerkes
Subject: [Tinycc-devel] Two compilers at once
Date: Fri, 24 May 2019 10:47:31 -0700

I would like to have two compilers active at the same time so i can recompile and hot-swap a function. ;On my journey, I noticed that making a new, second compiler before the first one compiles leads to strange behaviour. I am running macOS 10.14.5 with tcc 0.9.27.

// compile and run like this:
//
//   c++ -std=c++11 -ltcc tinycc-devel-example.cpp ; and ./a.out
//
// the `tcc_compile_string` step will fail with this error:
//
//   <string>: error: missing #endif
//
#include <cassert>
#include <cstdio>
#include "libtcc.h"

int main() {
  TCCState* a = nullptr;
  char (*A)(int) = nullptr;
  assert((a = tcc_new()) != nullptr);
  TCCState* b = tcc_new();  // remove this line to make the program work
  assert(tcc_set_output_type(a, TCC_OUTPUT_MEMORY) == 0);
  assert(tcc_compile_string(a, "char foo(int t) { return (char)t; }") != -1);
  assert(tcc_relocate(a, TCC_RELOCATE_AUTO) >= 0);
  assert((A = (char (*)(int))tcc_get_symbol(a, "foo")) != nullptr);
  printf("%d = A(0)\n", A(0));
}


As long as I make the second compiler after the first one compiles something, things work. is this a bug? Is using two compilers unsupported or prohibited?

-- karl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]