![]() Targets that have 32-bit pointers can usually use &mySymbol instead of the _symval operator. The compiler treats _symval(&mySymbol) in a special way that can represent all 32 bits, even when pointers are 16 bits. You must use the _symval operator, which is equivalent to a cast, because the 32-bit value of the linker symbol could be wider than a data pointer. Then, refer to the value of the linker symbol mySymbol as _symval(&mySymbol). If you are not using GCC extensions, declare it as “extern char”. If you are using GCC extensions, declare it as “extern void”. Linker symbols for an arbitrary address: In C code, declare this as an extern symbol. ![]() For example:Įxtern char data_sym extern int xyz printf ( "data_sym %lx \n ", _symval ( & data_sym )) /* these two are equivalent */ printf ( "data_sym %p \n ", & data_sym ) myvar = & xyz This works because function pointers “decay” to their address value when used without adornment. Then, refer to the value of the linker symbol using the same name. Linker symbols that represent a function address: In C code, declare the function as an extern function. The details differ depending on the type of linker symbol. The basic technique is to cause the compiler to create a “fake” C variable or function and take its address. For linker symbols, x is an address, and that address contains the value Y.īecause of this difference, there are some tricks to referring to linker symbols in C code. In C, x is a variable name with the address &x and content Y. Even though the C/C++ variable and the linker symbol have the same name, they don’t represent the same thing. To realize this variable, the compiler generates a linker symbol named x with the value &x. If “x” is used on the right-hand side of an expression, the compiler fetches the value Y. If you have a variable named x that contains the value Y, and you use the name “x” in your C program, you are actually referring to the contents of variable x. However, in C and C++ names mean something different. When you refer to the symbol by name in the linker command file or in an assembly file, you get that 32-bit integer value. The value represents the target address where that function or variable is located. The most common kind of symbol is generated by the compiler for each function and variable. The value is a 32-bit unsigned integer, even if it represents a pointer value on a target that has pointers smaller than 32 bits. Using Linker Symbols in C/C++ Applications ¶
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |