Thread: Variable declarations before main function parentheses?

  1. #16
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Ah, I guess it depends on how it's built. The arguments are passed as-is, but the program can expand them before main if it so chooses. Per Expanding wildcard arguments | Microsoft Docs:

    By default, wildcards aren't expanded in command-line arguments. You can replace the normal argument vector argv loading routine with a version that does expand wildcards by linking with the setargv.obj or wsetargv.obj file. If your program uses a main function, link with setargv.obj. If your program uses a wmain function, link with wsetargv.obj. Both of these have equivalent behavior.
    I found that a program built with MinGW does expand wildcards by default (it mimics the expected Unix behavior when it's run from CMD). But add int _CRT_glob = 0; to your code and this wildcard expansion is disabled.
    Last edited by christop; 04-26-2022 at 07:12 PM.

  2. #17
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    That's interesting.
    I don't have VS and don't feel like installing it so I can't test whether it links with the wildcard expansion by default.
    And I can't get the int _CRT_glob = 0; to work in CodeBlocks. It still expands the wildcards. I assume it's supposed to be global, and I tried it with and without extern.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #18
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    I think _CRT_glob is specifically for MinGW. Other compilers may have different methods to disable wildcard expansion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 04-15-2020, 12:49 AM
  2. Replies: 2
    Last Post: 03-25-2016, 05:34 AM
  3. Replies: 8
    Last Post: 01-31-2014, 03:52 AM
  4. Passing variable from an outside function to main?
    By ZeroDivision in forum C Programming
    Replies: 6
    Last Post: 11-08-2013, 08:32 PM
  5. Passing variable from function - main - function
    By ulti-killer in forum C Programming
    Replies: 2
    Last Post: 11-01-2012, 12:14 PM

Tags for this Thread