user-0 提问:  B_PTR( var )  ( (byte *) (void *) &(var) )的疑问

回复:
user: user-1
content: 引用 4 楼 zuixin369 的回复:[quote=引用 2 楼 zhao4zhong1 的回复:] //C++ Operators //  Operators specify an evaluation to be performed on one of the following: //    One operand (unary operator) //    Two operands (binary operator) //    Three operands (ternary operator) //  The C++ language includes all C operators and adds several new operators. //  Table 1.1 lists the operators available in Microsoft C++. //  Operators follow a strict precedence which defines the evaluation order of //expressions containing these operators.  Operators associate with either the //expression on their left or the expression on their right;    this is called //“associativity.” Operators in the same group have equal precedence and are //evaluated left to right in an expression unless explicitly forced by a pair of //parentheses, ( ). //  Table 1.1 shows the precedence and associativity of C++ operators //  (from highest to lowest precedence). // //Table 1.1   C++ Operator Precedence and Associativity // The highest precedence level is at the top of the table. //+------------------+-----------------------------------------+---------------+ //| Operator         | Name or Meaning                         | Associativity | //+------------------+-----------------------------------------+---------------+ //| ::               | Scope resolution                        | None          | //| ::               | Global                                  | None          | //| [ ]              | Array subscript                         | Left to right | //| ( )              | Function call                           | Left to right | //| ( )              | Conversion                              | None          | //| .                | Member selection (object)               | Left to right | //| ->               | Member selection (pointer)              | Left to right | //| ++               | Postfix increment                       | None          | //| --               | Postfix decrement                       | None          | //| new              | Allocate object                         | None          | //| delete           | Deallocate object                       | None          | //| delete[ ]        | Deallocate object                       | None          | //| ++               | Prefix increment                        | None          | //| --               | Prefix decrement                        | None          | //| *                | Dereference                             | None          | //| &                | Address-of                              | None          | //| +                | Unary plus                              | None          | //| -                | Arithmetic negation (unary)             | None          | //| !                | Logical NOT                             | None          | //| ~                | Bitwise complement                      | None          | //| sizeof           | Size of object                          | None          | //| sizeof ( )       | Size of type                            | None          | //| typeid( )        | type name                               | None          | //| (type)           | Type cast (conversion)                  | Right to left | //| const_cast       | Type cast (conversion)                  | None          | //| dynamic_cast     | Type cast (conversion)                  | None          | //| reinterpret_cast | Type cast (conversion)                  | None          | //| static_cast      | Type cast (conversion)                  | None          | //| .*               | Apply pointer to class member (objects) | Left to right | //| ->*              | Dereference pointer to class member     | Left to right | //| *                | Multiplication                          | Left to right | //| /                | Division                                | Left to right | //| %                | Remainder (modulus)                     | Left to right | //| +                | Addition                                | Left to right | //| -                | Subtraction                             | Left to right | //| <<               | Left shift                              | Left to right | //| >>               | Right shift                             | Left to right | //| <                | Less than                               | Left to right | //| >                | Greater than                            | Left to right | //| <=               | Less than or equal to                   | Left to right | //| >=               | Greater than or equal to                | Left to right | //| ==               | Equality                                | Left to right | //| !=               | Inequality                              | Left to right | //| &                | Bitwise AND                             | Left to right | //| ^                | Bitwise exclusive OR                    | Left to right | //| |                | Bitwise OR                              | Left to right | //| &&               | Logical AND                             | Left to right | //| ||               | Logical OR                              | Left to right | //| e1?e2:e3         | Conditional                             | Right to left | //| =                | Assignment                              | Right to left | //| *=               | Multiplication assignment               | Right to left | //| /=               | Division assignment                     | Right to left | //| %=               | Modulus assignment                      | Right to left | //| +=               | Addition assignment                     | Right to left | //| -=               | Subtraction assignment                  | Right to left | //| <<=              | Left-shift assignment                   | Right to left | //| >>=              | Right-shift assignment                  | Right to left | //| &=               | Bitwise AND assignment                  | Right to left | //| |=               | Bitwise inclusive OR assignment         | Right to left | //| ^=               | Bitwise exclusive OR assignment         | Right to left | //| ,                | Comma                                   | Left to right | //+------------------+-----------------------------------------+---------------+   我没有看懂，这些与我的问题有什么关联，能否说明白一些。[/quote] //| (type)           | Type cast (conversion)                  | Right to left |

user: user-2
content: 引用 3 楼 zuixin369 的回复:[quote=引用 1 楼 user-2 的回复:] 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下[/quote] 如keil c中的int是16位的，通用指针是24位的

user: user-0
content: 引用 2 楼 zhao4zhong1 的回复://C++ Operators //  Operators specify an evaluation to be performed on one of the following: //    One operand (unary operator) //    Two operands (binary operator) //    Three operands (ternary operator) //  The C++ language includes all C operators and adds several new operators. //  Table 1.1 lists the operators available in Microsoft C++. //  Operators follow a strict precedence which defines the evaluation order of //expressions containing these operators.  Operators associate with either the //expression on their left or the expression on their right;    this is called //“associativity.” Operators in the same group have equal precedence and are //evaluated left to right in an expression unless explicitly forced by a pair of //parentheses, ( ). //  Table 1.1 shows the precedence and associativity of C++ operators //  (from highest to lowest precedence). // //Table 1.1   C++ Operator Precedence and Associativity // The highest precedence level is at the top of the table. //+------------------+-----------------------------------------+---------------+ //| Operator         | Name or Meaning                         | Associativity | //+------------------+-----------------------------------------+---------------+ //| ::               | Scope resolution                        | None          | //| ::               | Global                                  | None          | //| [ ]              | Array subscript                         | Left to right | //| ( )              | Function call                           | Left to right | //| ( )              | Conversion                              | None          | //| .                | Member selection (object)               | Left to right | //| ->               | Member selection (pointer)              | Left to right | //| ++               | Postfix increment                       | None          | //| --               | Postfix decrement                       | None          | //| new              | Allocate object                         | None          | //| delete           | Deallocate object                       | None          | //| delete[ ]        | Deallocate object                       | None          | //| ++               | Prefix increment                        | None          | //| --               | Prefix decrement                        | None          | //| *                | Dereference                             | None          | //| &                | Address-of                              | None          | //| +                | Unary plus                              | None          | //| -                | Arithmetic negation (unary)             | None          | //| !                | Logical NOT                             | None          | //| ~                | Bitwise complement                      | None          | //| sizeof           | Size of object                          | None          | //| sizeof ( )       | Size of type                            | None          | //| typeid( )        | type name                               | None          | //| (type)           | Type cast (conversion)                  | Right to left | //| const_cast       | Type cast (conversion)                  | None          | //| dynamic_cast     | Type cast (conversion)                  | None          | //| reinterpret_cast | Type cast (conversion)                  | None          | //| static_cast      | Type cast (conversion)                  | None          | //| .*               | Apply pointer to class member (objects) | Left to right | //| ->*              | Dereference pointer to class member     | Left to right | //| *                | Multiplication                          | Left to right | //| /                | Division                                | Left to right | //| %                | Remainder (modulus)                     | Left to right | //| +                | Addition                                | Left to right | //| -                | Subtraction                             | Left to right | //| <<               | Left shift                              | Left to right | //| >>               | Right shift                             | Left to right | //| <                | Less than                               | Left to right | //| >                | Greater than                            | Left to right | //| <=               | Less than or equal to                   | Left to right | //| >=               | Greater than or equal to                | Left to right | //| ==               | Equality                                | Left to right | //| !=               | Inequality                              | Left to right | //| &                | Bitwise AND                             | Left to right | //| ^                | Bitwise exclusive OR                    | Left to right | //| |                | Bitwise OR                              | Left to right | //| &&               | Logical AND                             | Left to right | //| ||               | Logical OR                              | Left to right | //| e1?e2:e3         | Conditional                             | Right to left | //| =                | Assignment                              | Right to left | //| *=               | Multiplication assignment               | Right to left | //| /=               | Division assignment                     | Right to left | //| %=               | Modulus assignment                      | Right to left | //| +=               | Addition assignment                     | Right to left | //| -=               | Subtraction assignment                  | Right to left | //| <<=              | Left-shift assignment                   | Right to left | //| >>=              | Right-shift assignment                  | Right to left | //| &=               | Bitwise AND assignment                  | Right to left | //| |=               | Bitwise inclusive OR assignment         | Right to left | //| ^=               | Bitwise exclusive OR assignment         | Right to left | //| ,                | Comma                                   | Left to right | //+------------------+-----------------------------------------+---------------+   我没有看懂，这些与我的问题有什么关联，能否说明白一些。

user: user-0
content: 引用 1 楼 user-2 的回复:转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下

user: user-2
content: 引用 11 楼 zuixin369 的回复:[quote=引用 9 楼 user-2 的回复:] [quote=引用 7 楼 zuixin369 的回复:] [quote=引用 5 楼 user-2 的回复:] [quote=引用 3 楼 zuixin369 的回复:] [quote=引用 1 楼 user-2 的回复:] 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下[/quote] 如keil c中的int是16位的，通用指针是24位的[/quote]  即使没有相同的位数，24位的通用指针经强制转换16位的int，还会出错吗？ 另，你说的经过一次转换后就行了， #define  B_PTR( var )  ( (byte *) &(var) ) #define  B_PTR( var )  (  (void *) &(var) ) 你的意思定义成上述两种形式都是OK？[/quote] 应该用第一种形式 第二种形式是转换成void型指针了，赋值给其他变量没问题，而间接求值时还要转换 24位的通用指针经强制转换16位的int，有风险的，不能保证不出问题[/quote]  #define  B_PTR( var )  ( (byte *) &(var) ) 我认可这样的写法，但是该宏定义中间还转换为void* ，这样做的目的是什么，看见网上好多这样的写法[/quote] 很多的东西，实际上是同一个，转来转去的，到哪儿去找第一个真正这样写的人呢？只有他知道

user: user-0
content: 引用 10 楼 zhao4zhong1 的回复://| (type)           | Type cast (conversion)                  | Right to left | (type)操作符是按从右到左优先级结合的。 意思就是说比如： (type1)(type2)a的类型是type1 (type2)(type1)a的类型是type2  那为什么中间要用void*，这样的目的是什么，不可能没有目的吧

user: user-0
content: 引用 9 楼 user-2 的回复:[quote=引用 7 楼 zuixin369 的回复:] [quote=引用 5 楼 user-2 的回复:] [quote=引用 3 楼 zuixin369 的回复:] [quote=引用 1 楼 user-2 的回复:] 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下[/quote] 如keil c中的int是16位的，通用指针是24位的[/quote]  即使没有相同的位数，24位的通用指针经强制转换16位的int，还会出错吗？ 另，你说的经过一次转换后就行了， #define  B_PTR( var )  ( (byte *) &(var) ) #define  B_PTR( var )  (  (void *) &(var) ) 你的意思定义成上述两种形式都是OK？[/quote] 应该用第一种形式 第二种形式是转换成void型指针了，赋值给其他变量没问题，而间接求值时还要转换 24位的通用指针经强制转换16位的int，有风险的，不能保证不出问题[/quote]  #define  B_PTR( var )  ( (byte *) &(var) ) 我认可这样的写法，但是该宏定义中间还转换为void* ，这样做的目的是什么，看见网上好多这样的写法

user: user-1
content: //| (type)           | Type cast (conversion)                  | Right to left | (type)操作符是按从右到左优先级结合的。 意思就是说比如： (type1)(type2)a的类型是type1 (type2)(type1)a的类型是type2

user: user-2
content: 引用 7 楼 zuixin369 的回复:[quote=引用 5 楼 user-2 的回复:] [quote=引用 3 楼 zuixin369 的回复:] [quote=引用 1 楼 user-2 的回复:] 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下[/quote] 如keil c中的int是16位的，通用指针是24位的[/quote]  即使没有相同的位数，24位的通用指针经强制转换16位的int，还会出错吗？ 另，你说的经过一次转换后就行了， #define  B_PTR( var )  ( (byte *) &(var) ) #define  B_PTR( var )  (  (void *) &(var) ) 你的意思定义成上述两种形式都是OK？[/quote] 应该用第一种形式 第二种形式是转换成void型指针了，赋值给其他变量没问题，而间接求值时还要转换 24位的通用指针经强制转换16位的int，有风险的，不能保证不出问题

user: user-0
content: 引用 6 楼 zhao4zhong1 的回复:[quote=引用 4 楼 zuixin369 的回复:] [quote=引用 2 楼 zhao4zhong1 的回复:] //C++ Operators //  Operators specify an evaluation to be performed on one of the following: //    One operand (unary operator) //    Two operands (binary operator) //    Three operands (ternary operator) //  The C++ language includes all C operators and adds several new operators. //  Table 1.1 lists the operators available in Microsoft C++. //  Operators follow a strict precedence which defines the evaluation order of //expressions containing these operators.  Operators associate with either the //expression on their left or the expression on their right;    this is called //“associativity.” Operators in the same group have equal precedence and are //evaluated left to right in an expression unless explicitly forced by a pair of //parentheses, ( ). //  Table 1.1 shows the precedence and associativity of C++ operators //  (from highest to lowest precedence). // //Table 1.1   C++ Operator Precedence and Associativity // The highest precedence level is at the top of the table. //+------------------+-----------------------------------------+---------------+ //| Operator         | Name or Meaning                         | Associativity | //+------------------+-----------------------------------------+---------------+ //| ::               | Scope resolution                        | None          | //| ::               | Global                                  | None          | //| [ ]              | Array subscript                         | Left to right | //| ( )              | Function call                           | Left to right | //| ( )              | Conversion                              | None          | //| .                | Member selection (object)               | Left to right | //| ->               | Member selection (pointer)              | Left to right | //| ++               | Postfix increment                       | None          | //| --               | Postfix decrement                       | None          | //| new              | Allocate object                         | None          | //| delete           | Deallocate object                       | None          | //| delete[ ]        | Deallocate object                       | None          | //| ++               | Prefix increment                        | None          | //| --               | Prefix decrement                        | None          | //| *                | Dereference                             | None          | //| &                | Address-of                              | None          | //| +                | Unary plus                              | None          | //| -                | Arithmetic negation (unary)             | None          | //| !                | Logical NOT                             | None          | //| ~                | Bitwise complement                      | None          | //| sizeof           | Size of object                          | None          | //| sizeof ( )       | Size of type                            | None          | //| typeid( )        | type name                               | None          | //| (type)           | Type cast (conversion)                  | Right to left | //| const_cast       | Type cast (conversion)                  | None          | //| dynamic_cast     | Type cast (conversion)                  | None          | //| reinterpret_cast | Type cast (conversion)                  | None          | //| static_cast      | Type cast (conversion)                  | None          | //| .*               | Apply pointer to class member (objects) | Left to right | //| ->*              | Dereference pointer to class member     | Left to right | //| *                | Multiplication                          | Left to right | //| /                | Division                                | Left to right | //| %                | Remainder (modulus)                     | Left to right | //| +                | Addition                                | Left to right | //| -                | Subtraction                             | Left to right | //| <<               | Left shift                              | Left to right | //| >>               | Right shift                             | Left to right | //| <                | Less than                               | Left to right | //| >                | Greater than                            | Left to right | //| <=               | Less than or equal to                   | Left to right | //| >=               | Greater than or equal to                | Left to right | //| ==               | Equality                                | Left to right | //| !=               | Inequality                              | Left to right | //| &                | Bitwise AND                             | Left to right | //| ^                | Bitwise exclusive OR                    | Left to right | //| |                | Bitwise OR                              | Left to right | //| &&               | Logical AND                             | Left to right | //| ||               | Logical OR                              | Left to right | //| e1?e2:e3         | Conditional                             | Right to left | //| =                | Assignment                              | Right to left | //| *=               | Multiplication assignment               | Right to left | //| /=               | Division assignment                     | Right to left | //| %=               | Modulus assignment                      | Right to left | //| +=               | Addition assignment                     | Right to left | //| -=               | Subtraction assignment                  | Right to left | //| <<=              | Left-shift assignment                   | Right to left | //| >>=              | Right-shift assignment                  | Right to left | //| &=               | Bitwise AND assignment                  | Right to left | //| |=               | Bitwise inclusive OR assignment         | Right to left | //| ^=               | Bitwise exclusive OR assignment         | Right to left | //| ,                | Comma                                   | Left to right | //+------------------+-----------------------------------------+---------------+   我没有看懂，这些与我的问题有什么关联，能否说明白一些。[/quote] //| (type)           | Type cast (conversion)                  | Right to left | [/quote]  大侠，我始终没有明白，你说的这些与我问的有什么关联，求指教

user: user-0
content: 引用 5 楼 user-2 的回复:[quote=引用 3 楼 zuixin369 的回复:] [quote=引用 1 楼 user-2 的回复:] 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥  转换一次你的意思是下面的形式？ #define  B_PTR( var )  ( (byte *) &(var) )  指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥。这句话怎么理解，能够举个例子说明一下[/quote] 如keil c中的int是16位的，通用指针是24位的[/quote]  即使没有相同的位数，24位的通用指针经强制转换16位的int，还会出错吗？ 另，你说的经过一次转换后就行了， #define  B_PTR( var )  ( (byte *) &(var) ) #define  B_PTR( var )  (  (void *) &(var) ) 你的意思定义成上述两种形式都是OK？

user: user-1
content: //C++ Operators //  Operators specify an evaluation to be performed on one of the following: //    One operand (unary operator) //    Two operands (binary operator) //    Three operands (ternary operator) //  The C++ language includes all C operators and adds several new operators. //  Table 1.1 lists the operators available in Microsoft C++. //  Operators follow a strict precedence which defines the evaluation order of //expressions containing these operators.  Operators associate with either the //expression on their left or the expression on their right;    this is called //“associativity.” Operators in the same group have equal precedence and are //evaluated left to right in an expression unless explicitly forced by a pair of //parentheses, ( ). //  Table 1.1 shows the precedence and associativity of C++ operators //  (from highest to lowest precedence). // //Table 1.1   C++ Operator Precedence and Associativity // The highest precedence level is at the top of the table. //+------------------+-----------------------------------------+---------------+ //| Operator         | Name or Meaning                         | Associativity | //+------------------+-----------------------------------------+---------------+ //| ::               | Scope resolution                        | None          | //| ::               | Global                                  | None          | //| [ ]              | Array subscript                         | Left to right | //| ( )              | Function call                           | Left to right | //| ( )              | Conversion                              | None          | //| .                | Member selection (object)               | Left to right | //| ->               | Member selection (pointer)              | Left to right | //| ++               | Postfix increment                       | None          | //| --               | Postfix decrement                       | None          | //| new              | Allocate object                         | None          | //| delete           | Deallocate object                       | None          | //| delete[ ]        | Deallocate object                       | None          | //| ++               | Prefix increment                        | None          | //| --               | Prefix decrement                        | None          | //| *                | Dereference                             | None          | //| &                | Address-of                              | None          | //| +                | Unary plus                              | None          | //| -                | Arithmetic negation (unary)             | None          | //| !                | Logical NOT                             | None          | //| ~                | Bitwise complement                      | None          | //| sizeof           | Size of object                          | None          | //| sizeof ( )       | Size of type                            | None          | //| typeid( )        | type name                               | None          | //| (type)           | Type cast (conversion)                  | Right to left | //| const_cast       | Type cast (conversion)                  | None          | //| dynamic_cast     | Type cast (conversion)                  | None          | //| reinterpret_cast | Type cast (conversion)                  | None          | //| static_cast      | Type cast (conversion)                  | None          | //| .*               | Apply pointer to class member (objects) | Left to right | //| ->*              | Dereference pointer to class member     | Left to right | //| *                | Multiplication                          | Left to right | //| /                | Division                                | Left to right | //| %                | Remainder (modulus)                     | Left to right | //| +                | Addition                                | Left to right | //| -                | Subtraction                             | Left to right | //| <<               | Left shift                              | Left to right | //| >>               | Right shift                             | Left to right | //| <                | Less than                               | Left to right | //| >                | Greater than                            | Left to right | //| <=               | Less than or equal to                   | Left to right | //| >=               | Greater than or equal to                | Left to right | //| ==               | Equality                                | Left to right | //| !=               | Inequality                              | Left to right | //| &                | Bitwise AND                             | Left to right | //| ^                | Bitwise exclusive OR                    | Left to right | //| |                | Bitwise OR                              | Left to right | //| &&               | Logical AND                             | Left to right | //| ||               | Logical OR                              | Left to right | //| e1?e2:e3         | Conditional                             | Right to left | //| =                | Assignment                              | Right to left | //| *=               | Multiplication assignment               | Right to left | //| /=               | Division assignment                     | Right to left | //| %=               | Modulus assignment                      | Right to left | //| +=               | Addition assignment                     | Right to left | //| -=               | Subtraction assignment                  | Right to left | //| <<=              | Left-shift assignment                   | Right to left | //| >>=              | Right-shift assignment                  | Right to left | //| &=               | Bitwise AND assignment                  | Right to left | //| |=               | Bitwise inclusive OR assignment         | Right to left | //| ^=               | Bitwise exclusive OR assignment         | Right to left | //| ,                | Comma                                   | Left to right | //+------------------+-----------------------------------------+---------------+

user: user-2
content: 转换一次就够了 你的方法有问题。指针和unsigned int类型未必有相同的位数，考虑到可移植性，还是指针稳妥