tinycc | My fork of Fabrice Bellard 's Tiny C Compiler
kandi X-RAY | tinycc Summary
kandi X-RAY | tinycc Summary
TinyCC (or tcc) is short for Tiny C Compiler. This a clone of the mob development repo at
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tinycc
tinycc Key Features
tinycc Examples and Code Snippets
Community Discussions
Trending Discussions on tinycc
QUESTION
This is puzzling me: If I comment out everything from the #if to the #endif the program compiles in C99 (TinyCC). With the conditional in it gives the error ')' expected (got "0") at the line before the #if clause
...ANSWER
Answered 2021-Jul-14 at 11:46The preprocessor commonly does not know how to evaluate all C expressions. Its capabilities are quite limited.
If you comment out if line with #if
, the macro will not be evaluated. That's why you don't get an error.
But if the macro is evaluated you make the preprocessor parse the expression. Apparently it cannot do this.
QUESTION
I've noticed that with gcc
(but not clang
), const
(readonly) initialized data objects no longer show up as
R
data objects in nm
and instead they become D
(initialized section) objects.
That would suggest the data object will be placed in writable memory, however, when the same object file is linked with either gcc
or clang
(but not tcc
), then it seems to be placed in readonly memory anyway.
clang
doesn't seem to use these curious readonly-D
symbols (instead the object remains R
).
Tinycc does make such objects into D
symbols too, but those D
symbols doesn't seem to have that curious property that causes linkers to put them in readonly memory.
Can you explain what's going on here?
The script below demonstrates the behavior with gcc, clang, and tinycc used in all combinations as compilers and linkers:
...ANSWER
Answered 2021-Jan-31 at 15:23Most likely your gcc is configured with --enable-default-pie
(gcc -v
to check).
In PIE, readonlyObject
needs to be writable at program startup to allow dynamic relocation processing code to write the address of fn0
into its first field. To arrange for that, gcc places such objects into sections with .data.rel.ro
prefix, and the linker collects such sections separately from other .data
sections. The dynamic linker (or, in case of static PIEs, linked-in relocation processing code) can then mprotect
that region after writing into it.
Thus, with gcc (and implicit -fpie -pie
) you have:
readonlyObject
in.data.rel.ro
- classified by
nm
as "global data" - writable at program startup for relocation
- readonly when
main
is reached
With clang or gcc -fno-pie
you have:
readonlyObject
in.rodata
- classified by
nm
as "global constant" - readonly even on program startup
QUESTION
An example is something like Desmos (but as a desktop application). The function is given by the user as text, so it cannot be written at compile-time. Furthermore, the function may be reused thousands of times before it changes. However, a true example would be something where the function could change more frequently than desmos, and its values could be used more as well.
I see four methods for writing this code:
- Parse the user-defined function with a grammar every single time the function is called. (Slow with many function calls)
- Construct the syntax tree of the math expression so that the nodes contain function pointers to the appropriate math operations, allowing the program to skip parsing the text every single time the function is called. This should be faster than #1 for many function calls, but it still involves function pointers and a tree, which adds indirection and isn't as fast as if the functions were pre-compiled (and optimized).
- Use something like The Tiny C Compiler as the backend for dynamic code generation with libtcc to quickly compile the user's function after translating it into C code, and then use it in the main program. Since this compiler can compile something like 10,000 very simple programs on my machine per second, there should be next to no delay with parsing new functions. Furthermore, this compiler generates machine code for the function, so there are no pointers or trees involved, and optimization is done by TinyCC. This method is more daunting for an intermediate programmer like me.
- Write my own tiny compiler (not of C, but tailored specifically to my problem) to generate machine code almost instantly. This is probably 20x more work than #3, and doesn't do much in the way of future improvements (adding a summation operation generator would require me to write more assembly code for that).
Is there any easier, yet equally or more efficient method than #3, while staying in the realm of C++? I'm not experienced enough with lambdas and templates and the standard library to tell for sure if there isn't some abstract way to write this code easily and efficiently.
Even a method that is faster than #2 but slower than #3, and requires no dynamic code generation would be an improvement.
This is more of an intellectual curiosity than a real-world problem, which is why I am concerned so much with performance, and is why I wouldn't use someone else's math parsing library. It's also why I wouldn't consider using javascript or python interpreter which can interpret this kind of thing on-the-fly.
...ANSWER
Answered 2020-Sep-16 at 03:06I think something along the lines of your option 2 would be good. Except maybe to be a little easier would be to have an Expr
class with a float Expr::eval(std::unordered_map vars)
method. Then implement subclasses like Var
with a name
, Add
with left
and right
, Sub
, Mult
, Div
, etc all the functions you want. When evaluating you just pass in the map with like {{"x",3},{"y",4}}
or whatever and each Expr
object would pass that down to any subexpressions and then do it's operation.
I would think this would be reasonably fast. How complicated of expressions do you think your user's would be putting in? Most expressions probably won't require more than 10-20 function calls.
It can also get a lot faster
If you're trying to make something that graphs functions (or similar) you could speed this up considerably if you made your operations able to work with vectors of values rather than single scalar values.
Assuming you wanted to graph something like x^3 - 6x^2 + 11x - 6
with 10,000 points, if you had your Expr
objects only working on single values at a time, yeah this would be like ~10-15 function calls * 10,000 points = a lot jumping around!
However, if your Expr
objects could take arrays of values, like calling eval
with {{"x",[1,2,3...10000]}}
then this would only be ~10-15 function calls, total, into optimized C++. This could easily scale up to a larger number of points and still be very fast.
QUESTION
How set CMAKE_STATIC_LINKER_FLAGS
in CMakeLists.txt immediately after the executable file?
for example: I need:
tcc.exe
-arqc staticRun.lib CMakeFiles/staticRun.dir/utils/system.c.obj
but cmake after this settings:
set (CMAKE_AR C:/run/code/toolchains/c++/MinGW-tcc/bin/tcc.exe CACHE FILEPATH "" FORCE)
set (CMAKE_STATIC_LINKER_FLAGS -ar CACHE STRING "" FORCE)
add -ar
key like this:
tcc.exe qc staticRun.lib CMakeFiles/staticRun.dir/utils/system.c.obj
-ar
so, building the static library failed.
P.S.tcc.exe -ar - mean
...Tools: create library : tcc -ar [rcsv] lib.a files
ANSWER
Answered 2020-Jun-12 at 08:07The simplest is just to change the line that is used to run the static library with your custom semantics:
QUESTION
I wrote a simple win32 GUI application with buttons and other controls, in pure C, no MFC. I want to make it more accessible for those who can not use mouse.
First, my example code does not respond to
Tab
key to move focus from one button to another. I can press UI button using mouse, than it becomes focused and i can activate button usingSpace-bar
, but i can't move focus to other buttons usingTab
orShift+Tab
. How can i fix this?I want to assign keyboard cues (little underscores) to buttons, so user can use keyboard shortcuts to activate buttons.
I have google it around, but answers are hard googleable, so i need someone to point me to some documentation. A little piece of code would be very helpful.
Here is the code i have. I compile and run it on Linux using WINE + TinyCC
...ANSWER
Answered 2020-Apr-29 at 12:58It was simple. In main message processing loop, i call IsDialogMessage()
with proper HWND
. Then, if this function returns zero, i call normal TranslateMessage and DispatchMessage functions. Here is code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tinycc
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page