how to put char * argv[] to global variable

appqui-platform

I am just trying to write something like that:

u64 get_env(char *argv[]);

char* g_argv[];

static char * Sample ()
{
  return (char*)get_env(g_argv);
}

int main(int argc, char *argv[])
{
   g_argv = argv;
   Sample();
}
Getting error: 'g_argv' has an incomplete type

warning: array 'g_argv' assumed to have one element [enabled by default]

I've tried many different ways. How to write it right?

Jim Balter
int main(int argc, char *argv[])

Despite what it looks like, argv is not an array; arrays aren't first class objects in C and cannot be passed to functions, only their addresses can. So because argv is a parameter, it's actually a pointer to a pointer. For this reason I think it's better to tell the truth and use

int main(int argc, char** argv)

which is exactly equivalent to the above. This confusion in the language has led you to

char* g_argv[];

You're saying this is an array of pointers, without saying how big the array is, but that's not what you want; you want a pointer to the first of several pointers:

char** g_argv;

That fixes the problem you asked about, but I wonder about this declaration:

u64 get_env(char *argv[]);

Why declare it as returning u64 when the name and usage clearly indicate that it returns a char*? Actually, you should not be declaring it here at all ... it should be declared in a header file that specifies the API that includes get_env. Hopefully that header file declares it as returning a char*, and then you can remove the cast from

return (char*)get_env(g_argv);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How is `int main(int argc, char* argv<::>)` a valid signature of main?

分類Dev

C / C ++ char ** argv VS * argv []

分類Dev

How to Create a Global Variable with a condition

分類Dev

How to put variable as argument in system()

分類Dev

How to put a variable inside cURL?

分類Dev

What is a char** argv[] in C++?

分類Dev

strcpy crash with char *[] (ARGV Structure)

分類Dev

How to define global variable in PL/SQL in Oracle?

分類Dev

How can I write to a global variable in Aurelia?

分類Dev

How to initialise a global variable in unit test runs?

分類Dev

How to get LLVM global variable constant value?

分類Dev

How to increment value of global variable in assembly in linux

分類Dev

How to set a color as a global variable in PowerApps?

分類Dev

How to properly store a global variable in flask application

分類Dev

how to scanf a global variable outside the main?

分類Dev

How to put the value of an entry into a variable in tkinter

分類Dev

How to Set Global Variable Values in the onStart parameter of Shiny Application

分類Dev

How to access global variable from inside class's function

分類Dev

How do I populate an array with the output of a function that sets a global variable?

分類Dev

How to assign something to global variable from within FOR loop in batch

分類Dev

how to use a predefined global variable inside a function on a different file

分類Dev

How to set and retrieve the global variable's values in the feature file in karate?

分類Dev

How to put all my selected columns into a dummy variable?

分類Dev

NODEJS mongodb how to put variable inside like query

分類Dev

Put ligature char to a ComboBox text

分類Dev

How to printf ASCII using argv?

分類Dev

関数main(int argc、char * argv [])のパラメーターargv

分類Dev

C ++のchar ** argv []とは何ですか?

分類Dev

What is the issue in following conversion from argv[1] to char * string?

Related 関連記事

  1. 1

    How is `int main(int argc, char* argv<::>)` a valid signature of main?

  2. 2

    C / C ++ char ** argv VS * argv []

  3. 3

    How to Create a Global Variable with a condition

  4. 4

    How to put variable as argument in system()

  5. 5

    How to put a variable inside cURL?

  6. 6

    What is a char** argv[] in C++?

  7. 7

    strcpy crash with char *[] (ARGV Structure)

  8. 8

    How to define global variable in PL/SQL in Oracle?

  9. 9

    How can I write to a global variable in Aurelia?

  10. 10

    How to initialise a global variable in unit test runs?

  11. 11

    How to get LLVM global variable constant value?

  12. 12

    How to increment value of global variable in assembly in linux

  13. 13

    How to set a color as a global variable in PowerApps?

  14. 14

    How to properly store a global variable in flask application

  15. 15

    how to scanf a global variable outside the main?

  16. 16

    How to put the value of an entry into a variable in tkinter

  17. 17

    How to Set Global Variable Values in the onStart parameter of Shiny Application

  18. 18

    How to access global variable from inside class's function

  19. 19

    How do I populate an array with the output of a function that sets a global variable?

  20. 20

    How to assign something to global variable from within FOR loop in batch

  21. 21

    how to use a predefined global variable inside a function on a different file

  22. 22

    How to set and retrieve the global variable's values in the feature file in karate?

  23. 23

    How to put all my selected columns into a dummy variable?

  24. 24

    NODEJS mongodb how to put variable inside like query

  25. 25

    Put ligature char to a ComboBox text

  26. 26

    How to printf ASCII using argv?

  27. 27

    関数main(int argc、char * argv [])のパラメーターargv

  28. 28

    C ++のchar ** argv []とは何ですか?

  29. 29

    What is the issue in following conversion from argv[1] to char * string?

ホットタグ

アーカイブ