Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio C++ 2010 how can __argv be a null pointer?

int _tmain(int argc, _TCHAR* argv[])
{

    if (argc != 3) {
        printf("Format is straightline.exe <EO records file> <output file>");
        return 1;
    }
    string eoPath = string(__argv[1]);
    //...other stuff ...
}

If __argc == 3, how can __argv be a null pointer?

My debugger is telling me that __argv is pointing to 0x00000000 after the program crashed when I was trying to reference __argv[1] (and I have verified that __argc == 3). This is a minimal program and it happened in the beginning before I did any sort of processing.

like image 324
pete Avatar asked Sep 11 '25 10:09

pete


2 Answers

If this is complied as unicode, then __argv will be null, while __wargv will contain what you want. I believe that there is a __targv that should contain the command line arguments regardless of unicode or ascii.

But why use any of these if you can just use argv passed in as a parameter to _tmain?

like image 153
zastrowm Avatar answered Sep 13 '25 07:09

zastrowm


The pointer to __argv can (and will) be null in Unicode configurations.

like image 36
QuantumBlack Avatar answered Sep 13 '25 05:09

QuantumBlack