0

I have the following config file Config.cfg

[DD]
user=**
password=***
database=****
IPServidor=****
port=3306

[Machine]
Machine1=8
Temp=5=1001
Hum=7=1002
Link=8=1003
Volt=9=1004

With the usage of GLib GKeyFile Parser in this tutorial I would like to read the number of Machine1 which is 8.

So I copy-paste this part in main

int main()
{
 GKeyFile *keyfile;
 GKeyFileFlags flags;
 GError *error = NULL;
 gsize length;

 /* Create a new GKeyFile object and a bitwise list of flags. */
 keyfile = g_key_file_new ();
 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

 /* Load the GKeyFile from keyfile.conf or return. */
 if (!g_key_file_load_from_file (keyfile, "Config.conf", flags, &error))
 {
 g_error (error->message);
 return -1;
 }
}

but I have error

invalid conversion from 'int' to 'GKeyFileFlags'

Where is the error here?

dali1985
  • 3,263
  • 13
  • 49
  • 68
  • Are you trying to compile this C code as C++? In C, implicit conversion between `enum`s and `int` should happen... –  Jul 01 '13 at 10:57
  • Unfortunately yes. I am trying to compile a C code as C++. I wrote a huge project in C. I started a C++ project in Codeblocks but finally I used C code. Is there any solution in this case or I have to create a new C project? – dali1985 Jul 01 '13 at 11:14
  • I don't know, I don't use IDEs. But you'd better not compile C code as C++, just like you don't compile JavaScript with a Pascal compiler or Lisp with a Fortran compiler. They are different languages that have pretty much nothing to do with each other. Maybe your IDE has some settings for manually specifying which types of files should be compiled by which compiler. –  Jul 01 '13 at 11:16
  • so the credentials to access the database `user=root; password=password`. sooner or later somebody would figure the db host. and then they complain that *my server was hacked*. – devnull Jul 01 '13 at 11:21
  • I tried something as (GKeyFileFlags )(G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS) to pass as an argument and it helped! Old thread but hope it helps someone looking for again – Chakradhar K Sep 06 '19 at 09:46

1 Answers1

0

So you problem is that apparently you are trying to compile C code as C++, which it isn't, so the compiler complains. Modify your settings so that C source files are compiled by a C compiler, and C++ source files by a C++ compiler.