本文介绍了左倾投射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我最近更新了我的gcc版本(到gcc版本3.4.2 (mingw-special)),我得到了一个警告我不太清楚如何最好 解决: 警告:使用强制转换表达式作为左值不推荐使用 调用此警告的代码与PIDL(指向项目ID 列表的指针,这是一个Windows事物并且实际上并不太重要)有关。问题 是我有一个指向结构的指针(typedef''d到ITEMIDLIST)和 为了访问一些数据我必须移动一定数量字节数( 指针真正指向一个具有任意大小的内存块的数组,并且 结构只是一种接口这些块的方式),所以这就是我b $ b做了: ITEMIDLIST * pidl; int offset; ... (字符*)pidl + =偏移; 如何修复警告?优先不使用额外的 变量(例如char *)。 谢谢, - - Martijn http://www.sereneconcepts.nl 解决方案 在文章< 43 *********************** @ news.xs4all.nl>, Martijn< su *********************@hot-remove-mail.com>写道: 你可以做pidl =(ITEMIDLIST *)(((char *)pidl)+ offset)。 其他人可能会解决这个 类的东西的可移植性问题。我假设你知道对齐问题。 - Richard pidl =(ITEMIDLIST *)((char * )pidl + offset); - pete Hi,I recently updated my version of gcc (to gcc version 3.4.2(mingw-special) ), and I get a warning I am not too sure about how to bestsolve:warning: use of cast expressions as lvalues is deprecatedThe code that invokes this warning has to do with PIDLs (pointer to item idlist, which are a Windows thing and not too important really). The problemis that I have a pointer to a structure (typedef''d to ITEMIDLIST) and inorder to access some data I have to move over a certain amount of bytes (thepointer really points to an array with arbitrary-sized memory blocks, andthe structure is just a way to interface those blocks), so this is what Idid:ITEMIDLIST* pidl;int offset;...(char*)pidl += offset;What can I do to fix the warning? Preferebly without the use of an extravariable (e.g. a char*).Thanks,--Martijn http://www.sereneconcepts.nl 解决方案You could do "pidl = (ITEMIDLIST*)(((char *)pidl) + offset)".Someone else will probably address thet portability issues with thissort of thing. I assume you are aware of alignment issues.-- Richardpidl = (ITEMIDLIST *)((char *)pidl + offset);--pete 这篇关于左倾投射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-01 16:43