F
FMorales
aurgathor said:Let assume there is:
void f( char** str_ptr) {
}
if I want to call this from main with a predefined
string, I need to do:
char* str = "some_string";
f(&str);
but I'd like to do something like:
f(&("some_string"));
but this doesn't compile; I even tried:
f(&(char*)"some_string");
to no avail.
So, is there a way to call f() without having
to use an extra variable? If yes, how?
TIA
I believe what you're looking for is a feature (TMK) new to C99,
called, "Compound Literals". I will warn i'm not very familiar
w/ them, i've only done some basic things to get an understanding
of how they could benefit me. If you wish to research them, in my
C99 PDF their section is: 6.5.2.5 Compound Literals. With that
said, here's an example i compiled\ran ok w/ gcc as my compiler:
#include <stdio.h>
#include <stdlib.h>
void
foo( char **str )
{
printf( "%s\n", *str );
}
int
main( void )
{
foo( &(char *){"Hello World"} );
return 0;
}
Compiled w/: gcc -o foo foo.c -std=c99 . It ran just fine. I
apologize if there's any error's i missed, hopefully someone will
correct them. Hope it helps.
FMorales...