On 4/16/2016 at 1:47 PM, Enno Borgsteede <ennob...@gmail.com> wrote:

>> 1) Argc and argv are initially processed only by the OS, and never by the
>> linker or GTK or any compiler until after main() is called. Nothing you can
do
>> with the linker, GTK, or the compiler can change that fact.

>Not true. The program arguments are supplied by the OS, but not 
>necessarily as argc and argv.

That's funny! What are they supplied as? argz and argf?

>In a C program, they are prepared by the 
>init part of the run time library, which is linked against the main 
>program. That init part makes sure that argc and argv etc. are passed in 
>a format that main understands. Check

>http://stackoverflow.com/questions/3469955/in-c-how-is-the-main-method-initially-called

Notice how there is no accepted answer to that question? There is no such
thing as a "C program". There are programs that are written in C but there are
no C programs.

In reality, the operating system is what parses the command line only for the
number of arguments and the command line itself ... nothing more and nothing
less.

>and http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html

That's interesting but I'm not using Linux, I'm using GTK on a Win32 system.
And if you had actually read that article, you would know the only thing it
says about argc and argv is that it pushes them onto the stack ... nothing
more and nothing less.

>which is the URL shown in the best answer.

>> 2) Assemblers don't have their own calling conventions. OSes have their own
>> calling conventions and you pick a compiler with the same calling
convention,
>> or you hand program yourself, or your program will never work.

>OSes have calling conventions of their own, but compilers and languages 
>have them too. A Pascal compiler passes strings in another way than a C 
>compiler does.

A calling convention is a specification of how a callee passes parameters to a
caller, and whether the callee or caller clean up the stack afterwards. It is
not a property of the compiler or language, it is only a property of an API or
a DLL.

>When you write in assembler, and don't use the C startup libraries, you 
>will get the program arguments and environment in the format supplied by 
>the OS, or more exact the OS's program loader.

Exactly, and that format in the case of GTK is _cdecl, which means parameters
as specified in code are pushed on the stack in a right-to-left order and the
caller cleans up the stack when done. In ASM, this means you don't declare a
function as _cdecl, you simply push the expected parameters in the right order
and clean up the stack when the function returns.

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to