- 浏览: 235847 次
- 性别:
- 来自: 南京
最新评论
-
baby8117628:
vc下mp3 IDv1和IDV2的读取 -
gezexu:
你好,我按照你的步骤一步步进行但是安装libvorbis的时候 ...
linux如何搭建强大的FFMPEG环境 -
ini_always:
帅哥,转载也把格式做好点,另外出处也要注明一下吧。。。
MP3文件格式解析
在C语言代码中头文件中,充斥着下面的代码片段:
扩充C语言在编译的时候按照C++编译器进行统一处理,使得C++代码能够调用C编译生成的中间代码。
由于C语言的头文件可能被不同类型的编译器读取,因此写C语言的头文件必须慎重。
C++ compilers:
C++ compilers require that functions be declared with full prototypes, since C++ is more strongly typed than C. C functions and variables also need to be declared with the extern "C" directive, so that the names aren't mangled.
ANSI C compilers:
ANSI C compilers are not as strict as C++ compilers, but functions should be prototyped to avoid unnecessary warnings when the header file is #included.
non-ANSI C compilers:
Non-ANSI compilers will report errors if functions are prototyped.
These complications mean that your library interface headers must use some C preprocessor magic in order to be usable by each of the above compilers.
下面以一种标准的写法来示例如何准确的写可以安全被各种编译器使用的C文件。
Here are the relevant portions of that file:
/* __BEGIN_DECLS should be used at the beginning of your declarations,
so that C++ compilers don't mangle their names. Use __END_DECLS at
the end of C declarations. */
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
/* __P is a macro used to wrap function prototypes, so that compilers
that don't understand ANSI C prototypes still work, and ANSI C
compilers can issue warnings about type mismatches. */
#undef __P
#if defined (__STDC__) || defined (_AIX) \
|| (defined (__mips) && defined (_SYSTYPE_SVR4)) \
|| defined(WIN32) || defined(__cplusplus)
# define __P(protos) protos
#else
# define __P(protos) ()
#endif
These macros are used in "foo.h" as follows:
#ifndef _FOO_H_
#define _FOO_H_ 1
/* The above macro definitions. */
...
__BEGIN_DECLS
int foo __P((void));
int hello __P((void));
__END_DECLS
#endif /* !_FOO_H_ */
Note that the `#ifndef _FOO_H_' prevents the body of `foo.h' from being read more than once in a given compilation.
Feel free to copy the definitions of __P, __BEGIN_DECLS, and __END_DECLS into your own headers. Then, you may use them to create header files that are valid for C++, ANSI, and non-ANSI compilers.
Do not be naive about writing portable code. Following the tips given above will help you miss the most obvious problems, but there are definitely other subtle portability issues. You may need to cope with some of the following issues:
* Pre-ANSI compilers do not always support the void * generic pointer type, and so need to use char * in its place.
* The const and signed keywords are not supported by some compilers, especially pre-ANSI compilers.
* The long double type is not supported by many compilers.
对应c++的libraries 时文件代码的相关解释如下:
Creating libraries of C++ code should be a fairly straightforward process, because its object files differ from C ones in only three ways:
1. Because of name mangling, C++ libraries are only usable by the C++ compiler that created them. This decision was made by the designers of C++ in order to protect users from conflicting implementations of features such as constructors, exception handling, and RTTI.
2. On some systems, the C++ compiler must take special actions for the dynamic linker to run dynamic (i.e., run-time) initializers. This means that we should not call `ld' directly to link such libraries, and we should use the C++ compiler instead.
3. C++ compilers will link some Standard C++ library in by default, but libtool does not know which are these libraries, so it cannot even run the inter-library dependence analyzer to check how to link it in. Therefore, running `ld' to link a C++ program or library is deemed to fail. However, running the C++ compiler directly may lead to problems related with inter-library dependencies.
The conclusion is that libtool is not ready for general use for C++ libraries. You should avoid any global or static variable initializations that would cause an "initializer element is not constant" error if you compiled them with a standard C compiler.
There are other ways of working around this problem, but they are beyond the scope of this manual.
Furthermore, you'd better find out, at configure time, what are the C++ Standard libraries that the C++ compiler will link in by default, and explicitly list them in the link command line. Hopefully, in the future, libtool will be able to do this job by itself.
__BEGIN_DECLS ..... ..... __END_DECLS
#if defined(__cplusplus) #define __BEGIN_DECLS extern "C" { #define __END_DECLS } #else #define __BEGIN_DECLS #define __END_DECLS
扩充C语言在编译的时候按照C++编译器进行统一处理,使得C++代码能够调用C编译生成的中间代码。
由于C语言的头文件可能被不同类型的编译器读取,因此写C语言的头文件必须慎重。
C++ compilers:
C++ compilers require that functions be declared with full prototypes, since C++ is more strongly typed than C. C functions and variables also need to be declared with the extern "C" directive, so that the names aren't mangled.
ANSI C compilers:
ANSI C compilers are not as strict as C++ compilers, but functions should be prototyped to avoid unnecessary warnings when the header file is #included.
non-ANSI C compilers:
Non-ANSI compilers will report errors if functions are prototyped.
These complications mean that your library interface headers must use some C preprocessor magic in order to be usable by each of the above compilers.
下面以一种标准的写法来示例如何准确的写可以安全被各种编译器使用的C文件。
Here are the relevant portions of that file:
/* __BEGIN_DECLS should be used at the beginning of your declarations,
so that C++ compilers don't mangle their names. Use __END_DECLS at
the end of C declarations. */
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
/* __P is a macro used to wrap function prototypes, so that compilers
that don't understand ANSI C prototypes still work, and ANSI C
compilers can issue warnings about type mismatches. */
#undef __P
#if defined (__STDC__) || defined (_AIX) \
|| (defined (__mips) && defined (_SYSTYPE_SVR4)) \
|| defined(WIN32) || defined(__cplusplus)
# define __P(protos) protos
#else
# define __P(protos) ()
#endif
These macros are used in "foo.h" as follows:
#ifndef _FOO_H_
#define _FOO_H_ 1
/* The above macro definitions. */
...
__BEGIN_DECLS
int foo __P((void));
int hello __P((void));
__END_DECLS
#endif /* !_FOO_H_ */
Note that the `#ifndef _FOO_H_' prevents the body of `foo.h' from being read more than once in a given compilation.
Feel free to copy the definitions of __P, __BEGIN_DECLS, and __END_DECLS into your own headers. Then, you may use them to create header files that are valid for C++, ANSI, and non-ANSI compilers.
Do not be naive about writing portable code. Following the tips given above will help you miss the most obvious problems, but there are definitely other subtle portability issues. You may need to cope with some of the following issues:
* Pre-ANSI compilers do not always support the void * generic pointer type, and so need to use char * in its place.
* The const and signed keywords are not supported by some compilers, especially pre-ANSI compilers.
* The long double type is not supported by many compilers.
对应c++的libraries 时文件代码的相关解释如下:
Creating libraries of C++ code should be a fairly straightforward process, because its object files differ from C ones in only three ways:
1. Because of name mangling, C++ libraries are only usable by the C++ compiler that created them. This decision was made by the designers of C++ in order to protect users from conflicting implementations of features such as constructors, exception handling, and RTTI.
2. On some systems, the C++ compiler must take special actions for the dynamic linker to run dynamic (i.e., run-time) initializers. This means that we should not call `ld' directly to link such libraries, and we should use the C++ compiler instead.
3. C++ compilers will link some Standard C++ library in by default, but libtool does not know which are these libraries, so it cannot even run the inter-library dependence analyzer to check how to link it in. Therefore, running `ld' to link a C++ program or library is deemed to fail. However, running the C++ compiler directly may lead to problems related with inter-library dependencies.
The conclusion is that libtool is not ready for general use for C++ libraries. You should avoid any global or static variable initializations that would cause an "initializer element is not constant" error if you compiled them with a standard C compiler.
There are other ways of working around this problem, but they are beyond the scope of this manual.
Furthermore, you'd better find out, at configure time, what are the C++ Standard libraries that the C++ compiler will link in by default, and explicitly list them in the link command line. Hopefully, in the future, libtool will be able to do this job by itself.
发表评论
-
内存屏障
2010-02-26 11:03 1507处理器的乱序和并发执行 目前的高级处理器,为了提高内部逻辑元 ... -
函数调用堆栈分析
2010-02-26 10:53 1383理解调用栈最重要的两 ... -
mtrace检测内存泄露
2010-02-25 09:50 1089[url] http://math.acadiau.ca/AC ... -
c语言编程之字符串操作
2010-02-25 09:41 8621. //在s串中查找与s1相匹配的字符串,找到后用 ... -
linux C 链接库 so制作及调用[转]
2010-02-24 16:26 2579文章分类:C++编程 [文章作者:陈毓端 若转载请标注原文链 ... -
mtrace的使用
2010-02-24 16:02 1312对于内存溢出之类的麻烦可能大家在编写指针比较多的复杂的程序的时 ... -
单片机的C语言中位操作用法(转
2010-02-24 14:27 2212单片机的C语言中位操作用法 作者:郭天祥 在对单处机进 ... -
Linux下的itoa函数
2010-02-21 17:55 1765上篇文章说到linux需要it ... -
va_list、va_start、va_arg、va_end的原理与使用
2010-02-05 10:34 29031. 概述 由于在C语言中没有函数重载,解 ... -
快速排序(quickSort)
2010-02-04 10:50 8671. #include <stdio.h> ... -
C问题---itoa函数
2010-02-04 10:36 1046------------------------------ ... -
itoa函数及atoi函数
2010-02-04 10:35 1312C语言提供了几个标准库函数,可以将任意类型(整型、长整型、浮点 ... -
结构体零长度数组的作用
2010-02-04 10:21 1374在一些 C 语言编写的代码中,有时可以看到如下定义的结构: ... -
优化C代码常用的几招
2010-02-04 10:14 774性能优化方面永远注意8 ... -
我经常去的网站
2010-02-03 17:53 1623MFC相关网站 www.codeproject.com ht ... -
可重入函数与不可重入函数
2010-02-03 16:35 931原文地址:http://blog.chin ... -
linux线程池及其测试
2010-02-03 16:32 2360/*----------------------------- ... -
哈夫曼编码
2010-02-03 16:26 1315本文描述在网上能够找到的最简单,最快速的哈夫曼编码。本方法不使 ... -
优化变成了忧患:String.split引发的“内存泄露”
2010-02-01 17:39 1116一直赞叹Sun对待技术的 ... -
锁无关的(Lock-Free)数据结构——在避免死锁的同时确保线程
2010-01-26 14:47 906http://hi.baidu.com/%5F%E2%64%5 ...
相关推荐
JavaCC语法文件中定义了几个关键的保留字和结构,例如EOF、IGNORE_CASE、JAVACODE、LOOKAHEAD、MORE、PARSER_BEGIN、PARSER_END、SKIP、SPECIAL_TOKEN、TOKEN、TOKEN_MGR_DECLS。这些关键字有特定的用途,比如PARSER...
8. **编译预处理**:文件中的`__BEGIN_DECLS`和`__END_DECLS`宏用于在C++环境中开启和关闭声明的namespace保护,确保与C++标准库的兼容性。 通过`stdio.h`,程序员能够方便地处理各种输入输出任务,包括读写文本...
A DeclarationContext holds a reference to a v8::Context and keeps track of various declaration related counters to make it easier to track if global declarations in the presence of interceptors behave...
4. **cdefs.h**:包含了一些通用的定义和宏,比如`__BEGIN_DECLS`和`__END_DECLS`,用于在C++环境中正确地处理C语言的函数声明。 5. **fcntl.h**:提供了文件控制函数的声明,如`fcntl()`, 它可以用来改变文件描述...
为了深入理解,我们可以在代码编辑器(例如Visual Studio with Visual Assist插件)中对这个宏进行展开。 当第一次展开`GENERATED_BODY()`时,会得到如`CURRENT_FILE_ID___LINE___GENERATED_BODY`这样的临时字符串...
字节码生成器 这是一个Java程序,它... program -> decls stmts end decls -> int idlist ; idlist -> id { , id } stmts -> stmt [ stmts ] cmpdstmt-> '{' stmts '}' stmt -> assign | cond | loop assign ->
在类定义中,使用`//{{AFX_DATA_DECLS(MyDialog)}`和`//}}AFX_DATA_DECLS`包围的代码块内,添加如下代码: ```cpp afx_msg void OnBnClickedOk(); CString m_username; CString m_password; ``` `OnBnClickedOk`是...
有点基于 Clang 的 ASTVisitor 的工作原理,除了它使用虚拟方法,因为我懒得做“奇怪的重复模板”技巧来保存 vtable,因为模式往往不会那么大或经常解析 vtables 的性能访客类对任何人都有很大的不同。 基本上,...
- `compound_stmt`:包含局部变量声明`local_decls`和语句列表`stmt_list`的大括号包裹的结构。 - `local_decls`:函数内部变量声明,可以是另一个`local_decl`或为空。 - `if_stmt`:if条件语句,可以有else子句...
'begin' decls stmts 'end' decls --> [ 'int' idlist ';' ] [ 'real' idlist ';' ] [ 'bool' idlist ';' ] idlist --> id {',' id} stmts --> [ stmt [ stmts ] ] stmt --> assign | cond | loop | ...
我将遵循Aho等人在“编译器:原理,技术和工具”中给出的建议和步骤。 人对Java的一个子集。 我看过其他资料,例如Appel编写的Java中的Modern Compiler Implementation,但感到前者对所有相关概念给出了更详尽的...
Output registers encode semantic information in their name. Need to lookup a table built at decl time.Input registers are referred to by their semantic name rather ... Use the mapping build up the decls.
- 在编写C语言源代码时,可能需要包含PostgreSQL特定的头文件,如`postgres.h`、`fmgr.h`和`utils/geo_decls.h`,这些头文件定义了与PostgreSQL交互所需的函数和数据结构。 总的来说,通过C语言创建PostgreSQL外部...
yacc.y文件主要定义了语法规则,例如program、block、decls、statementlist等,并使用goto.c函数实现符号表、回填、创建节点、定义节点属性等功能。 五、实验结果 实验结果包括生成的中间代码序列和实验报告。实验...
C++(Qt)软件调试-静态分析工具clang-tidy是指使用clang-tidy对C++代码进行静态分析,以发现潜在问题和改进代码质量。clang-tidy是一个开源工具,支持C++/C/Objective-C语言,提供了一种基于AST(抽象语法树)的检查...
报告中给出了文法(CFG)的一部分,如类型定义(int、float、bool、char)、声明(decls)和语句(stmts)等的词法规则。 2. **语法分析器**:这部分通常采用LR(1)分析法,对词法分析器输出的符号流进行解析,构建...
程序-> decls stmts结束decls-> int idlist; idlist-> id {,id} stmts-> stmt [stmts] cmpdstmt->'{'stmts'}' stmt->分配| cond | 环形分配-> id = expr; cond-> if'('rexp')'cmpdstmt [else cmpdstmt] 循环-> ...
13. `-Wredundant-decls`:当代码中出现重复声明时发出警告。 在实际项目中,开发者通常会结合使用这些选项,以提高代码质量和可维护性。例如,`-Wall -Wextra -Werror`是一个常见的组合,它确保了代码不仅没有语法...
在网页开发中,有时我们需要动态地改变页面的样式,以...然而,需要注意的是,这种做法可能会增加页面加载时间和内存占用,因此在可能的情况下,还是建议将样式信息保留在独立的CSS文件中,以提高页面性能和维护性。