首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

指针强制转换有关问题 (int*)(char*)buffer

2013-10-12 
指针强制转换问题 (int*)(char*)buffer刚刚在看opencv源代码的cvcanny的时候,看到这样一段代码:cv::AutoBu

指针强制转换问题 (int*)(char*)buffer
刚刚在看opencv源代码的cvcanny的时候,看到这样一段代码:
cv::AutoBuffer<char> buffer;
int* mag_buf[3];
mag_buf[0] = (int*)(char*)buffer;
有没有高手解释一下最后一行代码的意思是什么啊?指针这样强制转换的意义何在? 指针 buffer 强制转换
[解决办法]

引用:
Quote: 引用:

强制转换在于buffer本身的地址不变,但是其意义改变了。

Quote: 引用:

刚刚在看opencv源代码的cvcanny的时候,看到这样一段代码:
cv::AutoBuffer<char> buffer;
int* mag_buf[3];
mag_buf[0] = (int*)(char*)buffer;
有没有高手解释一下最后一行代码的意思是什么啊?指针这样强制转换的意义何在?

mag_buf[0] = (int*)(char*)buffer;这个为什么要先强制转换char* 然后再转换成int*,直接转到int*不行吗


对象怎么能直接转换成指针?(char*)应该是个重载运算
[解决办法]
计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……

对学习编程者的忠告:
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步对应汇编一行!

单步类的实例“构造”或“复制”或“作为函数参数”或“作为函数返回值返回”或“参加各种运算”或“退出作用域”的语句对应的汇编代码几步后,就会来到该类的“构造函数”或“复制构造函数”或“运算符重载”或“析构函数”对应的C/C++源代码处。

VC调试时按Alt+8、Alt+7、Alt+6和Alt+5,打开汇编窗口、堆栈窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应堆栈、内存和寄存器变化,这样过一遍不就啥都明白了吗。
对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
(Turbo C或Borland C用Turbo Debugger调试,Linux或Unix下用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)
//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 
[解决办法]

//+------------------+-----------------------------------------+---------------+

热点排行