Tiny "c" info

Started by jcfuller, August 26, 2020, 04:55:23 AM

Previous topic - Next topic

RAW

The 2KB executable file size is surprisingly tiny.

RAW

JoeC4281

Here's how I use TinyC with BCX...
$NOWIN
$LEANANDMEAN

#INCLUDE "stdio.h"
#INCLUDE "windows.h"
#INCLUDE "stdlib.h"

PRINT "Hello, World"


Translate...
bc test -m -z -q

Run...
"E:\Program Files\tcc\tcc.exe" -run test.c
Hello, World


Joe

MrBcx

#17
Okay ... I have some helpful info to get you started.

1)   Put $NOWIN inside your TEST.bas:

      $NOWIN
      PRINT "Hello, World"

2) Translate with BCX
    BC Test

3) Open Test.c and edit this line:

// *************************************************
// Instruct Linker to Search Object/Import Libraries
// *************************************************

#if !defined(__GNUC__) && !defined(__TINYC__)

4) Save Test.c

5) Compile with TCC:

    tcc Test.c

It works for me, it should work for you.


I will include && !defined(__TINYC__)  in the upcoming version of BCX 8.0.4
That will make things a little bit easier for you.

Much of the runtime library that BCX emits uses default arguments which is a C++ feature and is
available as an extension in Pelles C and the old Lcc-Win32 C compilers.  If you're set on torturing
yourself using TCC, you will also need the InsertOptionalArg utility that fills in the default args
for TCC and GCC.  Ref:  https://bcxbasiccoders.com/smf/index.php?topic=536.msg2424#msg2424

Also, much of what BCX emits demands a current and fairly complete set of Win32 API files. 

Consider your C compilers carefully.


JohnClaw

I like BCX very much but it uses LCC compiler that consumes more than 100 mb of disk space. I dream to find a smaller one compiler that could make the tiniest executables. Is there any alternative to Tiny C? Btw, how can i convert BCX .bas files to asm code? I heard that NASM can create the smallest executables and wish to try it.

JohnClaw

I tried to follow your instructions but got this error:

tcc: error: library 'kernel32.lib' not found
tcc: error: library 'user32.lib' not found
tcc: error: library 'gdi32.lib' not found
tcc: error: library 'comctl32.lib' not found
tcc: error: library 'advapi32.lib' not found
tcc: error: library 'winspool.lib' not found
tcc: error: library 'shell32.lib' not found
tcc: error: library 'ole32.lib' not found
tcc: error: library 'oleaut32.lib' not found
tcc: error: library 'uuid.lib' not found
tcc: error: library 'odbc32.lib' not found
tcc: error: library 'odbccp32.lib' not found
tcc: error: library 'winmm.lib' not found
tcc: error: library 'comdlg32.lib' not found
tcc: error: library 'imagehlp.lib' not found
tcc: error: library 'version.lib' not found

MrBcx

Quote from: JohnClaw on August 31, 2023, 03:13:27 PM
Does exist some way to use Tiny C with BCX?

Hello and welcome to the forum.

I have not messed around with Tcc for 15 years.  What I remember is that TCC was
able to compile many of the sample BCX console apps and a few of simple GUI apps. 

To get started, I suggest writing a simple Test.bas:   PRINT "Hello, World"

Translate Test.bas with BCX like this at command prompt:

BC Test

BCX BASIC to C/C++ Translator (c) 1999-2023 by Kevin Diggins
Version 8.0.4 (08/31/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
[Lines In: 1] [Lines Out: 239] [Statements: 2] [Time: 0.01 Sec's]
BCX translated [Test.Bas] to [Test.C] for a C Compiler

Try to compile with TCC like this:

TCC Test.c  -luser32 -lkernel32 -ladvapi32 -lcomctl32 -lshell32 -lole32 -lgdi32 -lcomdlg32

I know many of those libraries are not needed.  I remember that those were the most commonly
needed when compiling BCX generated code.  It might take some trial and error but you will get
there if you stick with it.

Don't be afraid of error messages or warnings.  They happen and they can teach you what you
need to fix.  If you get stuck, ask questions here.  Someone will try to help you.

  ~MrBcx~


JohnClaw

Does exist some way to use Tiny C with BCX?

psbrsneiman

There is a separate download for https://download.savannah.gnu.org/releases/tinycc/winapi-full-for-0.9.27.zip

I had to add it when I liked to add Unicode to my programs.


MrBcx

Tcc has a fraction of the headers and libs that one finds in other compiler systems.



Robert

Quote from: MrBcx on August 26, 2020, 04:10:50 PM
Sorry ... still no love ...

error: bad operand with opcode 'pushq'

Thanks for that.

I had tcc setup a few years ago and am trying again but am having trouble with complaints about the Windows headers. I don't know if I have that patience for this anymore. It used to be fun but after a few times it gets old real fast.

MrBcx

Sorry ... still no love ...

error: bad operand with opcode 'pushq'

Robert

Quote from: MrBcx on August 26, 2020, 03:22:14 PM
And the answer is: NO

C:\Temp\tcc-win64>tcc -c  test.c -m64

test.c:239: error: bad operand with opcode 'pushl'


SOURCE OF ERROR:

#elif defined( __MINGW32__ ) || defined( __TINYC__)
__asm__("pushl %0" : : "r" (arg));     <<<-------------------------------------

Instead of "pushl" try "pushq"

MrBcx

And the answer is: NO

C:\Temp\tcc-win64>tcc -c  test.c -m64

test.c:239: error: bad operand with opcode 'pushl'


SOURCE OF ERROR:

#elif defined( __MINGW32__ ) || defined( __TINYC__)
__asm__("pushl %0" : : "r" (arg));     <<<-------------------------------------

MrBcx

Quote from: Robert on August 26, 2020, 02:26:25 PM

Hi MrBCX:

If I recall correctly, claims were made in the past that tcc would compile 64 bit inlne assembly code. I never tried it. It would be interesting to see if BCX_DYNACALL worked as a 64 bit tcc compile.

Maybe I'll take up that challenge just to satisfy curiosity.   

The MakeGuidFromString () that I posted yesterday was initially much easier to
implement but limited to 32-bit apps only because of its dependency on Dynacall:

FUNCTION MakeGuidFromString (MyStr$, MyGUID AS LPGUID)
  FUNCTION = UuidFromString (LIB "Rpcrt4.dll", MyStr$, MyGUID)
END FUNCTION


Overcoming that 32-bit limitation is why I decided rewrite it thusly :


'FUNCTION MakeGuidFromString (MyStr$, MyGUID AS LPGUID)
'  '***************************************************
'! typedef int( __stdcall *UIDFS )(PCHAR,LPGUID);
'  '***************************************************
'  DIM hDll AS HMODULE
'  DIM MakeUUID AS UIDFS
'  LOCAL RetCode

'  hDll = LOADLIBRARY("Rpcrt4.dll")
'  IF hDll = NULL THEN
'    PRINT  "Could not load Rpcrt4.dll"
'    FUNCTION = 0
'  END IF

'  $IFDEF UNICODE
'    MakeUUID = GetProcAddress(hDll, "UuidFromStringW")
'  $ELSE
'    MakeUUID = GetProcAddress(hDll, "UuidFromStringA")
'  $ENDIF

'  IF MakeUUID = NULL THEN
'    PRINT  "Could not locate the function: UuidFromString()"
'    FreeLibrary(hDll)
'    FUNCTION = 0
'  END IF

'  RetCode = MakeUUID (MyStr$, MyGUID)
'  FreeLibrary(hDll)
'  FUNCTION = RetCode
'END FUNCTION

Robert

Quote from: MrBcx on August 26, 2020, 01:56:26 PM
Robert,

Yes ... I visited github before I responded to JC's post.

I observed a number of forks (mirrors)

https://github.com/search?o=desc&q=tinycc&s=updated&type=Repositories

Frankly, I don't see the allure with so many better alternatives available.

Yes ... it's fast, small, and free.

Reminds me of an old engineering joke:  Cheap, fast, and correct ... pick two.

Hi MrBCX:

If I recall correctly, claims were made in the past that tcc would compile 64 bit inlne assembly code. I never tried it. It would be interesting to see if BCX_DYNACALL worked as a 64 bit tcc compile.