English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 31 January 2021, 11:42   #1
sparhawk
Registered User
 
sparhawk's Avatar
 
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
sparhawk is offline  
Old 31 January 2021, 11:44   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
What runtime library are you using? The default is IXEmul.library but libNix is preferred.
Samurai_Crow is offline  
Old 31 January 2021, 12:28   #3
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
I'm using -lnix13.
sparhawk is offline  
Old 31 January 2021, 12:47   #4
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
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;
}
compiled with
Code:
m68k-amigaos-gcc -mcrt=nix13 -s -Os -o args args.c
works fine in (emulated) A500
alkis is offline  
Old 31 January 2021, 12:56   #5
sparhawk
Registered User
 
sparhawk's Avatar
 
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
sparhawk is offline  
Old 31 January 2021, 14:01   #6
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by sparhawk View Post
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
Can you provide a minimum compilable source code that exhibits the problem?
alkis is offline  
Old 31 January 2021, 16:46   #7
sparhawk
Registered User
 
sparhawk's Avatar
 
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?
sparhawk is offline  
Old 31 January 2021, 18:32   #8
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
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
alkis is offline  
Old 31 January 2021, 18:42   #9
sparhawk
Registered User
 
sparhawk's Avatar
 
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.
sparhawk is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:04.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.14927 seconds with 15 queries