Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

In the tests for blocks runtime implementation, I'm having a test fail because a block that takes a variable number of arguments is not getting the right value for a double that is passed in.

The test code is available here. I can't see anything wrong with it, and it obviously works elsewhere.

with the printf's uncommented I have this output:

i: 10
i: 20

i: 30
d: 4.94066e-324
c: ''

got different wrong result: 30

(and when I redirect the output to a file, the c: '' is c: '^@')

It looks to me like it is pulling something of the wrong size off the argument list, or something the wrong size is being put on the list.

This is being compiled with clang, you can see the flags used in the script that runst the tests here (I add -mfloat-abi=hard).

Without the -mfloat-abi=hard I get this error:

clang: warning: unknown platform, assuming -mfloat-abi=soft
/usr/bin/ld.gold: error: testbin/variadic.o uses VFP register arguments, output does not
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What is causing my double to be wrong? Can I fix it? How?

Here are the sizes: sizeof(40.0) == 8 sizeof(float) == 4 sizeof(double) == 8 In the same test, two ints are pulled off the argument list correctly;

Not sure what this means exactly, but wrote a little function to help me investigate further:

double DoubleSwap( double d ){

            double d;
            unsigned char b[8];
    } dat1, dat2;

    dat1.d = d;
    dat2.b[0] = dat1.b[7];
    printf("swap %d", dat1.b[0]);
    dat2.b[1] = dat1.b[6];
    printf("swap %d", dat1.b[1]);
    dat2.b[2] = dat1.b[5];
    printf("swap %d", dat1.b[2]);
    dat2.b[3] = dat1.b[4];
    printf("swap %d", dat1.b[3]);
    dat2.b[4] = dat1.b[3];
    printf("swap %d", dat1.b[4]);
    dat2.b[5] = dat1.b[2];
    printf("swap %d", dat1.b[5]);
    dat2.b[6] = dat1.b[1];
    printf("swap %d", dat1.b[6]);
    dat2.b[7] = dat1.b[0];
    printf("swap %d", dat1.b[7]);
    return dat2.d;

which gives me a lovely 1 0 0 0 0 0 0 0 for what I pull off the stack. Is this my 40.0 or is this argument list malformed somehow?

share|improve this question

closed as off-topic by goldilocks Dec 21 '14 at 19:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – goldilocks
If this question can be reworded to fit the rules in the help center, please edit the question.

It would be good if you could paste your code here instead of linking to github. In case your code on github changes in the future, the question would still be valid. –  Krzysztof Adamski Nov 15 '12 at 7:16
Could you please check the values of sizeof(40.0), sizeof(float) and sizeof(double) in your environment (compiled with the same compiler options etc)? –  Krzysztof Adamski Nov 15 '12 at 7:19
@Krzysztof Adamski -It's not my code, I don't know if I am allowed to post it. I will update my question with the sizes you asked for. –  Josh at AffinityAmp Nov 15 '12 at 20:37
Ok, so it's not the float vs double issue. The code itself is OK so it may be a compiler bug. I don't have access to my RaspberryPi right now so I can't check. What you could do is to change addthem() block to normal C function and test if that works ok. –  Krzysztof Adamski Nov 16 '12 at 7:16
@KrzysztofAdamski I was gone from home for a couple weeks, but I changed it to a normal variadic function and it worked perfectly. –  Josh at AffinityAmp Dec 2 '12 at 19:08

Browse other questions tagged or ask your own question.