Page 2 of 2

Re: startup getmainargs

Posted: Mon Jun 23, 2025 11:29 am
by nullplan
kerravon wrote: Mon Jun 23, 2025 5:25 am If the compiler uses - or can use - stack calling convention, then:

#define va_arg(ap, type) *(type *)(ap += sizeof(type), ap - sizeof(type))
Wow, such portable! It doesn't work on any platform I know except i386.
kerravon wrote: Mon Jun 23, 2025 5:25 am My application suite doesn't pass "short",
That is no issue because the type given to va_arg must be a promoted type, i.e. int or bigger. GCC warns me that executing va_arg(ap, short) will abort at run time.

Re: startup getmainargs

Posted: Sat Jun 28, 2025 2:58 pm
by iProgramInCpp
Octocontrabass wrote: Fri Jun 13, 2025 11:28 pm I was thinking more along the lines of having the entry point be inside (the equivalent of) msvcrt.dll. This is actually how dynamic linking works in Linux: dynamically linked ELF executables specify that ld-linux.so contains the entry point.
In Win32 applications, main() is called by a function that goes by either `_mainCRTStartup` or `_start` or `start` (I believe it depends on which compiler toolset it was compiled with). But that function is linked into the application.

Dynamic linking on Windows works in basically the same way as on Linux, yes, but the thing doing the loading is not msvcrt.dll. It's actually ntdll.dll. When a process is created, the main thread's first instruction is in ntdll.dll. Then, it loads all of the DLLs, and then the application. For each of the DLLs, its entry point (DllMain) is called with DLL_PROCESS_ATTACH (well, er, again, _DllMainCRTStartup etc), and then the application's entry point is called, which eventually calls main().
kerravon wrote: Sat Jun 14, 2025 1:18 am Universal across all compilers and linkers worldwide.
All compilers... that implement the C90 standard in a way that completely abides by the standard?