Re: Problems with C floats

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...
puts(1, "\n> printf test:\n") 
s = define_c_proc(libc, "printf", {C_POINTER, C_INT, C_DOUBLE, C_INT, C_FLOAT}) 
format = allocate_string("Here are 4 numbers: %d, %.3f, %d, %e\n") 
c_proc(s, {format, 111, 222.222, 333, 444.4444}) 

Now, I may be doing something foolishly wrong, but the results I'm getting from my GTK programs indicate that something isn't getting through properly, and it only happens when C_FLOATs are involved.

I think that printf expects a double float (64-bits) with the %f format. And if you send a known float in C code, the compiler will cast it to a double (which is what I suspect is happening in the example I posted). In this case, it expects a double, and ends up reading past your 32-bit float, because that's all it knows. There's no way for printf to be able to tell what you've actually passed to it, other than the clues you give in the format string.

Can you create a minimal code sample (C and euphoria) that demonstrates the problem?

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu