Normally you would follow the instructions in the manual, and pass pointers to the arguments provided by main
, so that gstreamer can remove the arguments which it handles.
#include <stdio.h>
#include <gst/gst.h>
int main ( int argc, char *argv[] )
{
gst_init (&argc, &argv);
// handle the remaining argc values of argv
If you want to create your own arguments, then create the same sort of array which main
would have:
void gst_init(int *argc, char **argv[])
{
// strip one argument
--*argc;
++*argv;
}
void foo ()
{
int argc = 2;
char* args[] = {"myvalue1", "myvalue2"};
char** argv = args;
for(int i= 0; i < argc; ++i)
printf("%s\n", argv[i]);
gst_init(&argc, &argv);
for(int i= 0; i < argc; ++i)
printf("%s\n", argv[i]);
}
If you're not using C99, it's easier to have a separate pointer to the local array of string literals. Using C99, you could just write char** argv = (char*[]){"myvalue1", "myvalue2"};
to start with a pointer to the first element in an anonymous array.
You need to pass a pointer to a variable pointing to the array rather than a pointer to the first element in the array; in the first case the degradation of an array parameter to a pointer achieves the same effect as the second case declaring a pointer local variable - you then can pass the address of this variable and the function can modify it. sizeof( args) is 8 on a 32bit machine as the compiler deduces the number of elements in the array; sizeof(argv) is 4, therefore ++args would move the pointer to the end of the array rather than to the next element as ++argv does. The compiler protects you from such an operation.
But normally you'd use it in the way the manual suggests.