Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Markus Wichmann <nullplan@gmx.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Floating point support not loaded |
| Date | 2012-03-26 10:29 +0200 |
| Organization | 1&1 Internet AG |
| Message-ID | <20m549-jhr.ln1@voyager.wichi.de.vu> (permalink) |
| References | <58a3b95c-55ea-4d4c-9da0-4c837348b5d0@12g2000vba.googlegroups.com> <jkkdb0$v8g$1@dont-email.me> <9a135814-206f-482c-a3f0-6e199b690b31@l7g2000vbw.googlegroups.com> <2ce3e2be-5693-4766-847b-363c75ac22fd@i2g2000vbv.googlegroups.com> <lnlimphees.fsf@nuthaus.mib.org> |
On 24.03.2012 22:34, Keith Thompson wrote:
> lolzy@live.nl writes:
>> /*
>> * Encode a string according to http://tools.ietf.org/html/rfc3986#section-2.1.
>> */
>> void urlEncode(char *string)
>> {
>> float test = sqrt(9);
>> int i = 0;
>> char *buf = KhSafeMalloc(((strlen(string) * 3) + 1) * sizeof(char)),
>> *end = buf;
>>
>> while (string[i] != '\0')
>> {
>> if ((unsigned char) isalnum(string[i]) || string[i] == '-' ||
>> string[i] == '_' || string[i] == '.' || string[i] == '~')
>> *end++ = string[i];
>> else if (string[i] == ' ')
>> *end++ = '+';
>> else
>> end += sprintf(end, "%%%.2X", string[i]);
>>
>> ++i;
>> }
>>
>> *end = '\0';
>> strcpy(string, buf);
>> free(buf);
>> }
>>
>>
>> 'float test = sqrt(9)' did the trick :-)
>
> It's likely that you don't actually have to *execute* the call to the
> sqrt() function to cause floating point support to be loaded. Try
> something like:
>
> float test = 0 ? sqrt(9) : 0;
>
> or perhaps even:
>
> sqrt;
>
> The latter is not a call to sqrt; it's an expression that evaluates to
> the address of the sqrt function. Since the result is discarded, it
> shouldn't generate any actual code, but it might force the compiler to
> load the floating-point code anyway.
>
Ever heard of dead code elimination? It's a very basic optimization that
would remove the reference to sqrt() and therefore the need to link
against libm (or whatever that system's equal of it is).
> In both cases, a sufficiently clever compiler can recognize that the
> code has no effect and eliminate it -- but your compiler is
> insufficiently clever either to load the floating-point code or to
> recognize that it doesn't need it.
>
That's another can of worms. The way I see it, the designers of that
system's *scanf() did a bad job, because they depend on floating-point
support at runtime, but don't tell anyone during link time. My take on
it is that the compiler tries linking without libm and if that doesn't
work, tries it with libm. Maybe even something bigger, like linking
against nothing but libc, writing down all the "undefined reference"
errors and looking up the symbols in the libraries directory, then
linking in all the necessary libraries. Basically what you would get
with GNU ld and zsh and
ld -I/lib/ld-linux.so.2 -o output *.o --as-needed {/usr,}/lib/**/*.so
But somehow those guys wrote scanf() to not directly reference libm, so
this code doesn't see that it should include libm.
See the problem? The compiler can have all optimizations in the world,
here the linker and library conspire together to not make it work. If
you ask me, switch compilers!
> Of course you should have "#include <math.h>" if you refer to the sqrt
> function.
>
That's true, too.
Ciao,
Markus
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Floating point support not loaded lolzy@live.nl - 2012-03-24 03:04 -0700
Re: Floating point support not loaded Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-24 04:15 -0700
Re: Floating point support not loaded Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-24 08:05 -0400
Re: Floating point support not loaded lolzy@live.nl - 2012-03-24 10:15 -0700
Re: Floating point support not loaded lolzy@live.nl - 2012-03-24 10:51 -0700
Re: Floating point support not loaded Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-24 14:27 -0400
Re: Floating point support not loaded Keith Thompson <kst-u@mib.org> - 2012-03-24 14:34 -0700
Re: Floating point support not loaded Markus Wichmann <nullplan@gmx.net> - 2012-03-26 10:29 +0200
Re: Floating point support not loaded James Kuyper <jameskuyper@verizon.net> - 2012-03-26 06:48 -0400
Re: Floating point support not loaded Markus Wichmann <nullplan@gmx.net> - 2012-03-26 13:31 +0200
Re: Floating point support not loaded James Kuyper <jameskuyper@verizon.net> - 2012-03-26 08:42 -0400
csiph-web