Jump to content
Fraser

_argc

Recommended Posts

When I run my program from the IDE of 11.3 I am finding that _argc is 0 when I have not set any parameters.  So _argv[0] is not the program name as is the documented functionality.  I've not seen this before with any other version of C++ Builder.  If I set a parameter then _argc will be 1 and _argv[0] will be the parameter so there is not an error in how I use these variables.  I made a small test program but the problem would not show up.

Share this post


Link to post
7 hours ago, Fraser said:

I am finding that _argc is 0 when I have not set any parameters.  So _argv[0] is not the program name as is the documented functionality.

Putting the program name in argv[0] is only a convention, not a guarantee.  It depends on how the caller passes parameters when spawning the process.  And it is possible to spawn a process without the program name as the first parameter.

 

You can instead use ParamStr(0) (or Application->ExeName in VCL) to get the program name.

Share this post


Link to post

The standard says when argc>0 argv[0] holds the program name or is empty.  What I see is my parameter, which is neither of those.

Share this post


Link to post

My program works as expected outside of the IDE.  There is clearly a bug with C++ Builder 11.3.

Share this post


Link to post
1 hour ago, Fraser said:

The standard says when argc>0 argv[0] holds the program name or is empty.  What I see is my parameter, which is neither of those.

But you said originally that in your case argc was equal to zero (ie it is NOT > 0). 

Share this post


Link to post

It was said it's either

  1. argc == 0
  2. argc >= 1, with argc[0] being the first parameter, not the program name/path, as expected

 

I agree that it's more than odd and against everything else I've seen. For sure, nobody enforces it, and you can even omit the program name yourself by using things like CreateProcess(..).

However, ISO/IEC 9899 is pretty clear on that:

Quote

If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters

 

PS: It's probably a regression by this bugfix which was closed in April:

https://quality.embarcadero.com/browse/RSP-41397

https://quality.embarcadero.com/browse/RSP-41179

Edited by Der schöne Günther

Share this post


Link to post

It appears to unresolved with 11.3.  There is a few duplicate reports so it has been noticed by many people.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×