![]() |
![]() |
#1 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
gcc-bebbo: argc is always 0
I was wondering if this is a bug, or am I missing some library, because when I try to parse commandline arguments, they don't exist. "argc" is always 0.
I' using gcc from bebbo: https://github.com/bebbo/amiga-gcc |
![]() |
![]() |
#2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,224
|
What runtime library are you using? The default is IXEmul.library but libNix is preferred.
|
![]() |
![]() |
#3 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
I'm using -lnix13.
|
![]() |
![]() |
#4 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 732
|
There is no problem with argc.
This as args.c Code:
#include <stdio.h> int main(int argc, char *argv[]) { printf("Argc = %d\n", argc); for(int i = 0; i < argc; ++i) printf("arg(%d) = \"%s\"\n", i, argv[i]); return 0; } Code:
m68k-amigaos-gcc -mcrt=nix13 -s -Os -o args args.c |
![]() |
![]() |
#5 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Strange. My commandline looks like this.
Code:
m68k-amigaos-gcc -D AMIGA_OS --save-temps -fverbose-asm -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti -std=c++11 -O2 -mregparm -fno-rtti -O3 -DNDEBUG -Wl,--enable-auto-import CMakeFiles/TestMemfill.dir/main.cpp.o -o ../bin/TestMemfill.exe -Wl,--out-implib,../bin/libTestMemfill.dll.a -L/opt/amiga/utils/lib -lAmigaUtils -lAmigaGCCUtils |
![]() |
![]() |
#6 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 732
|
Quote:
|
|
![]() |
![]() |
#7 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
I compiled bebbos repo using regparm and I can see in monam that my main expects argc and argv in d0/a0. When I put __stdargs in front of main() then it works, because the startup code uses parameter passing on the stack, instead of registers.
Is this a bug or am I missing something when I compiled gcc? AFAIK it should use the same calling convention as compiled, right? or is there some header where the correct main() is declared? |
![]() |
![]() |
#8 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 732
|
It is working as designed. You should have the __stdargs in front of your main.
I tried the same on linux, has the same behavior. Code:
alex[0]@omen 13$ cat >args.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Argc = %d\n", argc); for(int i = 0; i < argc; ++i) printf("arg(%d) = \"%s\"\n", i, argv[i]); return 0; } alex[0]@omen 13$ gcc -o args args.c alex[0]@omen 13$ ./args 1 2 3 4 Argc = 5 arg(0) = "./args" arg(1) = "1" arg(2) = "2" arg(3) = "3" arg(4) = "4" alex[0]@omen 13$ gcc -mregparm=2 -o args args.c cc1: warning: ‘-mregparm’ is ignored in 64-bit mode alex[0]@omen 13$ gcc -mregparm=2 -m32 -o args args.c alex[0]@omen 13$ ./args 1 2 3 4 Argc = -135120888 |
![]() |
![]() |
#9 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Thanks! I was a bit surprised, about that, as I would think that the compile should select the correct calling convention for main, regardless of how it is compiled.
OK. It's not as bad as I feared, as I know now how to get around it. ![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
gcc .lib | mritter0 | Coders. C/C++ | 13 | 27 October 2018 02:13 |
[E] argc, argv example | r-tea | Coders. Language | 3 | 19 June 2017 23:28 |
gcc linker | mritter0 | Coders. C/C++ | 3 | 21 December 2014 16:54 |
From gcc to vbcc. | Cowcat | Coders. General | 9 | 06 June 2014 14:45 |
|
|