Friday, August 28, 2015
Friday, July 24, 2015
Locale
The value LC_ALL(0x0) for category names the program’s entire locale
LC_CTYPE(char type) affects the behavior of
the character handling functions and the multibyte and wide character functions.
LC_NUMERIC affects the decimal-point character for the formatted input/output functions and the string conversion functions, as well as the
nonmonetary formatting information returned by the localeconv function
char *setlocale(int category, const char *locale_to_be_set):
A value of "C" for locale_to_be_set specifies the minimal environment for C translation(At program startup, the equivalent of setlocale(LC_ALL, "C"); is executed.).A value of "" specifies the locale-specific native environment.
If a pointer to a string is given for locale and the selection can be honored, the
setlocale function returns a pointer to the string associated with the specified
category for the new locale.
LC_CTYPE(char type) affects the behavior of
the character handling functions and the multibyte and wide character functions.
LC_NUMERIC affects the decimal-point character for the formatted input/output functions and the string conversion functions, as well as the
nonmonetary formatting information returned by the localeconv function
char *setlocale(int category, const char *locale_to_be_set):
A value of "C" for locale_to_be_set specifies the minimal environment for C translation(At program startup, the equivalent of setlocale(LC_ALL, "C"); is executed.).A value of "" specifies the locale-specific native environment.
If a pointer to a string is given for locale and the selection can be honored, the
setlocale function returns a pointer to the string associated with the specified
category for the new locale.
Floating-point environment(fenv)
The type fenv_t represents the entire floating-point environment.
The type fexcept_t represents the floating-point status flags collectively, including any status the implementation associates with the flags.
a function call is assumed to require default floating-point control modes, unless its
documentation promises otherwise(The macro FE_DFL_ENV
represents the default floating-point environment — the one installed at program startup
— and has type ‘‘pointer to const-qualified fenv_t’’).
The FENV_ACCESS pragma provides a means to inform the implementation when a
program might access the floating-point environment to test floating-point status flags or
run under non-default floating-point control modes.The FENV_ACCESS macro is scopable(zxxu),for eaxmple,When inside a compound statement, the pragma takes effect from its occurrence until another FENV_ACCESS pragma is encountered (including within a
nested compound statement), or until the end of the compound statement).
EXAMPLE:
#include <fenv.h>
void f(double x)
{
#pragma STDC FENV_ACCESS ON
void g(double);
void h(double);
/* ... */
g(x + 1);
h(x + 1);
/* ... */
}
the function g might depend on status flags set as a side effect of the first x + 1, or the second
x + 1 might depend on control modes set as a side effect of the call to function g, and so on.
EXAMPLE:Call f if ‘‘invalid’’ is set, then g if ‘‘overflow’’ is set:
#include <fenv.h>
/* ... */
{
#pragma STDC FENV_ACCESS ON
int set_excepts;
feclearexcept(FE_INVALID | FE_OVERFLOW);
// maybe raise exceptions
set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
if (set_excepts & FE_INVALID) f();
if (set_excepts & FE_OVERFLOW) g();
/* ... */
}
The type fexcept_t represents the floating-point status flags collectively, including any status the implementation associates with the flags.
a function call is assumed to require default floating-point control modes, unless its
documentation promises otherwise(The macro FE_DFL_ENV
represents the default floating-point environment — the one installed at program startup
— and has type ‘‘pointer to const-qualified fenv_t’’).
The FENV_ACCESS pragma provides a means to inform the implementation when a
program might access the floating-point environment to test floating-point status flags or
run under non-default floating-point control modes.The FENV_ACCESS macro is scopable(zxxu),for eaxmple,When inside a compound statement, the pragma takes effect from its occurrence until another FENV_ACCESS pragma is encountered (including within a
nested compound statement), or until the end of the compound statement).
EXAMPLE:
#include <fenv.h>
void f(double x)
{
#pragma STDC FENV_ACCESS ON
void g(double);
void h(double);
/* ... */
g(x + 1);
h(x + 1);
/* ... */
}
the function g might depend on status flags set as a side effect of the first x + 1, or the second
x + 1 might depend on control modes set as a side effect of the call to function g, and so on.
EXAMPLE:Call f if ‘‘invalid’’ is set, then g if ‘‘overflow’’ is set:
#include <fenv.h>
/* ... */
{
#pragma STDC FENV_ACCESS ON
int set_excepts;
feclearexcept(FE_INVALID | FE_OVERFLOW);
// maybe raise exceptions
set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
if (set_excepts & FE_INVALID) f();
if (set_excepts & FE_OVERFLOW) g();
/* ... */
}
7.4 Character handling(ctype)
The header <ctype.h> declares several functions useful for classifying and mapping
characters.166) In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro EOF(0xffFFffFF). If the
argument has any other value, the behavior is undefined.
The term printing character refers to a member of a locale-specific set of characters, each
of which occupies one printing position on a display device; the term control character
refers to a member of a locale-specific set of characters that are not printing
characters.
The isalpha function tests for any character for which isupper or islower is true,
or any character that is one of a locale-specific...
The isblank function tests for any character that is a standard blank character or is one
of a locale-specific set of characters for which isspace is true and that is used to
separate words within a line of text. The standard blank characters are the following:
space (' '), and horizontal tab ('\t').
The isspace function tests for any character that is a standard white-space character or
is one of a locale-specific set of characters. The standard white-space characters are the following: space (' '), form feed ('\f'), new-line
('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').(blank<space,LF,VT,FF,CR属于space但不属于blank)
isxdigit: 0~9 a~f A~F
characters.166) In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro EOF(0xffFFffFF). If the
argument has any other value, the behavior is undefined.
The term printing character refers to a member of a locale-specific set of characters, each
of which occupies one printing position on a display device; the term control character
refers to a member of a locale-specific set of characters that are not printing
characters.
The isalpha function tests for any character for which isupper or islower is true,
or any character that is one of a locale-specific...
The isblank function tests for any character that is a standard blank character or is one
of a locale-specific set of characters for which isspace is true and that is used to
separate words within a line of text. The standard blank characters are the following:
space (' '), and horizontal tab ('\t').
The isspace function tests for any character that is a standard white-space character or
is one of a locale-specific set of characters. The standard white-space characters are the following: space (' '), form feed ('\f'), new-line
('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').(blank<space,LF,VT,FF,CR属于space但不属于blank)
isxdigit: 0~9 a~f A~F
Standard headers
Standard headers may be included in any order; each may be included more than once in
a given scope, with no effect different from being included only once, except that the
effect of including <assert.h> depends on the definition of NDEBUG:The assert macro is redefined according to the current state of NDEBUG each time that
<assert.h> is included.
Provided that a library function can be declared without reference to any type defined in a
header, it is also permissible to declare the function and use it without including its
associated header.
There is a sequence point immediately before a library function returns(一般来说,sequence point是分号).
函数签名和宏签名可以相同,以下是例子:
— by use of its associated header (possibly generating a macro expansion)
#include <stdlib.h>
const char *str;
/* ... */
i = atoi(str);
— by use of its associated header (assuredly generating a true function reference)
#include <stdlib.h>
#undef atoi //明确取消宏定义,只保留函数定义
const char *str;
/* ... */
i = atoi(str);
or
#include <stdlib.h>
const char *str;
/* ... */
i = (atoi)(str);//采用括号来避免宏展开,否则possibly generating a macro expansion
— by explicit declaration
extern int atoi(const char *);
const char *str;
/* ... */
i = atoi(str);
168
a given scope, with no effect different from being included only once, except that the
effect of including <assert.h> depends on the definition of NDEBUG:The assert macro is redefined according to the current state of NDEBUG each time that
<assert.h> is included.
Provided that a library function can be declared without reference to any type defined in a
header, it is also permissible to declare the function and use it without including its
associated header.
There is a sequence point immediately before a library function returns(一般来说,sequence point是分号).
函数签名和宏签名可以相同,以下是例子:
— by use of its associated header (possibly generating a macro expansion)
#include <stdlib.h>
const char *str;
/* ... */
i = atoi(str);
— by use of its associated header (assuredly generating a true function reference)
#include <stdlib.h>
#undef atoi //明确取消宏定义,只保留函数定义
const char *str;
/* ... */
i = atoi(str);
or
#include <stdlib.h>
const char *str;
/* ... */
i = (atoi)(str);//采用括号来避免宏展开,否则possibly generating a macro expansion
— by explicit declaration
extern int atoi(const char *);
const char *str;
/* ... */
i = atoi(str);
168
6.3.2.1 Lvalues, arrays, and function designators
Anlvalue is an expression with an object type or an incomplete type other than void.A modifiable lvalue is an lvalue that does not have array type, does
not have an incomplete type, does not have a const-qualified type, and if it is a structure
or union, does not have any member (including, recursively, any member or element of
all contained aggregates or unions) with a const-qualified type.
not have an incomplete type, does not have a const-qualified type, and if it is a structure
or union, does not have any member (including, recursively, any member or element of
all contained aggregates or unions) with a const-qualified type.
Linkages of identifiers
An identifier declared in different scopes or in the same scope more than once can be made to refer to the same object or function by a process called linkage. There are three kinds of linkage: external, internal, and none.
For an identifier declared with the storage-class specifier extern, if the prior declaration specifies internal or
external linkage, the linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
declaration specifies no linkage, then the identifier has external linkage
If the declaration of a file scope identifier for an object or a function contains the storageclass
specifier static, the identifier has internal linkage
Each declaration of an identifier with no linkage denotes a unique entity such as an identifier declared to be a function parameter or a block scope
identifier for an object declared without the storage-class specifier extern.
For an identifier declared with the storage-class specifier extern, if the prior declaration specifies internal or
external linkage, the linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
declaration specifies no linkage, then the identifier has external linkage
If the declaration of a file scope identifier for an object or a function contains the storageclass
specifier static, the identifier has internal linkage
Each declaration of an identifier with no linkage denotes a unique entity such as an identifier declared to be a function parameter or a block scope
identifier for an object declared without the storage-class specifier extern.
Subscribe to:
Posts (Atom)