confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Confuse-devel] CFG_SIMPLE_INT on 64bit machine


From: Martin Hömberg
Subject: [Confuse-devel] CFG_SIMPLE_INT on 64bit machine
Date: Sat, 24 Apr 2010 16:09:53 +0200

Hello.

First and foremost: Thank you very much for producing such a helpful
library as libconfuse. I am using it to configure a small molecular
dynamics program, that I have written for my PhD in physics. It worked
great so far. However, I am now experiencing a small problem. I am not
sure, if you consider this as being a bug, but it took me half a day to
figure out what is going on.

The problem is that the name "CFG_SIMPLE_INT" suggests, that it operates
on an "int", but in fact it operates on a "long". On my 64bit machine
(Intel(R) Xeon(R) CPU E5420  @ 2.50GHz), sizeof(int)==4 and
sizeof(long)==8. If I now use CFG_SIMPLE_INT() on an int, and there is
something else stored in memory behind this int, it gets overwritten by
CFG_SIMPLE_INT(). 

The problem can be illustrated by the following code, where a[0] is
changed by an option, but a[1] should remain constant which it does not
in my case.

------------------------------------------
#include <stdio.h>
#include <confuse.h>

static int a[2] = {0, 4};

static cfg_opt_t opts[] = {
        CFG_SIMPLE_INT("b", &a[0]),
        CFG_END()
};

int main(int argc, char **argv)
{
        cfg_t *cfg;

        printf("1. a=%d b=%d\n", a[0], a[1]);

        cfg = cfg_init(opts, CFGF_NOCASE);
        if (cfg_parse(cfg, "config.txt")) {
                printf("Couldn't read config.txt. Goodbye.\n");
                return 1;
        }
        
        printf("2. a=%d b=%d\n", a[0], a[1]);

        return 0;
}
------------------------------------------

The configuration looks like this:
------------------------------------------
b = 25
------------------------------------------

The output looks like this:
------------------------------------------
hicegate1:~/test $ gcc confusebug.c -o bug -I../local/include
-L../local/lib -lconfuse -O2
hicegate1:~/test $ ./bug
1. a=0 b=4
2. a=25 b=0
------------------------------------------


If you consider this as a bug, then please fix it. If not, then it is
worth mentioning on your website. If you need further information about
my software/hardware then please let me know.


Best wishes from Göttingen, Germany,


Martin Hömberg









reply via email to

[Prev in Thread] Current Thread [Next in Thread]