The optimization of C language library function compiling

Source: Internet
Author: User
Tags printf

Some library functions in the C language are optimized at compile time.

As in GCC

LOG2 (1) is optimized to be constant

But log2 (20) evaluates values at run time

Fabs will be optimized into machine (assembler) Instructions Fabs

So even if you don't have header files that contain fabs declarations, you can successfully compile and run

Programs with fabs functions

.....................................................................

(int&) A and * ((int*) &a) are the same

Think of the 32 digits on the &a address as Int.

..................................................................

The C language standard provides a data type long long

The current platform, long Long is a 8-byte 64-bit integer

The range of numbers represented is [ -2^63, 2^63-1]

So how do I enter the output of this type of data?

Long long test;

scanf ("%lld", &test);

printf ("%lld", test);

Under Gcc4+linux (2.6.15), such input and output is no problem.

But under Windows

Some old compilers, this code doesn't work correctly.

The reason is that c-runtime-library does not support this parameter

Underneath the xp+devc++4.9.

This has to become a special way of Windows. Specify type

%LLD have to be replaced with%I64D.

---------------------------------------------------------------

How to read all the memory data in a double

typedef Union
{
Double value;
struct
{
unsigned int lsw;
unsigned int msw;
} parts;
} Ieee_double_shape_type;
/* Get two bit ints from a double. */

#define Extract_words (IX0,IX1,D)
do {
Ieee_double_shape_type Ew_u;
Ew_u.value = (d);
(ix0) = EW_U.PARTS.MSW;
(ix1) = EW_U.PARTS.LSW;
} while (0)

How to output a complete floating-point number

Double D1;
Char str1[64];
d1=0.681638760023334166733241952779893935; 36
Dtoa (str1, D1, 40);
printf ("D1 =%s \ r \ n", str1);

---------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.