2

I try to setup a c programm using the libconfig. There is example1.c:

int main() 
{   
  const char **channel;

  config_t config;

  config_init(&config);

  config_read_file(&config, "example.cfg");
     if( config_lookup_string(&config,"value.channel",&channel) == CONFIG_FALSE)  
     {
        printf("Failed to read fields\n");
        return 1;  
     }
       printf("argumente = %s\n", (char *)channel);
       return 0; 
}

and the example.cfg file

value = { channel = "hello"; }

if I compile it

gcc example1.c -lconfig

it says:

example1.c:39:3: Warning: delivery of arguments 3 from »config_lookup_string« of a incompatible pointer
/usr/include/libconfig.h:244:26: Detailed: »const char **« expected, but argument has typ »const char ***«

The funny thing is it works... the output is: argumente = hello

How can I get rid of this warning ?

If I change the decleration to const char *channel and the output printf("argumente = %s\n", channel);, I receive a segfault at start and a warning at compiling like ... Detailed: »const char **« expected, but argument has typ »const char *«

timrau
  • 22,578
  • 4
  • 51
  • 64
Fendrix
  • 556
  • 2
  • 11
  • 34

1 Answers1

1

You just need to get rid of one * in your declaration of channel. If you do that, you can also remove the cast in your printf call.

The reason it's "working" now is that cast is hiding a second warning about your printf format. Your program is behaving just like the extra * was removed already - just in a confusing way.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • changed to const char *channel; and at the end printf("argumente = %s\n", channel); but I still get Segfault when starting... – Fendrix Sep 14 '12 at 15:31
  • @Fendrix, you must have changed something else - there's no way you could get that error message given your original example. How can it be expecting a `char *` one time and a `char **` another? – Carl Norum Sep 15 '12 at 00:34