Tiny CRT example by Vortex

Started by Vortex, October 03, 2023, 02:42:35 PM

Previous topic - Next topic

MrBcx

I moved this discussion into its own topic. 

I want to keep the BCX + UCRT discussion on topic.

Thanks for understanding.

Vortex

#4
Hi Robert,

The startup module does not depend on msvcrt.dll. Since BCX's PRINT command is translated to printf, we need to import it from msvcrt.lib

printfx("Hello world!")

FUNCTION printfx(myString AS STRING) AS INTEGER

LOCAL hHandle AS HANDLE
LOCAL WrittenBytes AS DWORD

    hHandle = GetStdHandle(STD_OUTPUT_HANDLE)

    WriteFile(hHandle, myString, lstrlen(myString), &WrittenBytes, 0)

    FUNCTION = WrittenBytes

END FUNCTION


My printfx function is a very simple one and it can only handle strings. As you can see, it has no any connection with msvcrt.dll




Robert

Quote from: Vortex on October 03, 2023, 02:42:35 PM
Hi Kevin,

The same hello world application built with Pelles C weights 36.5 Kb. With custom C run-time startup modules, the same application has a size of only 3 Kb. Of course, my tiny C run time library does not provide any memory initialization system. This method can be used with MS VC and MinGW. The UCRT approach is more professional as it provides all the functionality of the traditional C run-time library. The purpose of my example is to create very small applications like Masm\Poasm executables. The C run-time modules in the attachment can be converted to BCX.

Hi Vortex:

Thanks for this.

Instead of linking using

msvcrt.lib, ucrt.lib, vcruntime.lib

I am wondering if the msvcrt.lib can be substituted with your startup ?

From what I have read, startup is the only reason that msvcrt.lib is needed.

I'm also wondering about this

Quote
The license that Microsoft imposes on the Windows runtime SDK makes it impossible for the gcc/mingw-w64 developers to use the official CRT .lib files.

quoted from

How to correctly link to UCRT (and why it works that way)ΒΆ

at

https://mingwpy.github.io/ucrt.html

MrBcx

Hi Erol -- Smaller is a side effect of UCRT, not a goal. 

Here are some of the benefits of using the UCRT:

Improved ISO C99 conformance: The UCRT includes many functions and macros that were added or updated to improve ISO C99 conformance

This means that your code can take advantage of the latest C language features and standards.

Code quality and security improvements: The UCRT includes updates and improvements to address code quality and security issues

By upgrading to the UCRT, you can benefit from these enhancements and ensure that your code is more robust and secure.

Compatibility with newer versions of Visual C++: The UCRT is designed to work with newer versions of Visual C++. By upgrading your code to use the UCRT, you can ensure compatibility with the latest development tools and libraries.

I'm going to focus my UCRT studies on the MSVC compiler. 

Vortex

Hi Kevin,

The same hello world application built with Pelles C weights 36.5 Kb. With custom C run-time startup modules, the same application has a size of only 3 Kb. Of course, my tiny C run time library does not provide any memory initialization system. This method can be used with MS VC and MinGW. The UCRT approach is more professional as it provides all the functionality of the traditional C run-time library. The purpose of my example is to create very small applications like Masm\Poasm executables. The C run-time modules in the attachment can be converted to BCX.