亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我有一個帶有條件的for循環如下:

我有一個帶有條件的for循環如下:

C++
慕婉清6462132 2019-06-02 17:01:03
 uint index = ...// const float *bufferPtr = ...// uint stride = ...// uint vertexCount = ...for (uint i = 0; i < vertexCount; i++) {     float xVal = *bufferPtr++;     float yVal = *bufferPtr++;     float zVal = *bufferPtr++;     bufferPtr += stride;     if (i == index) {         qDebug() << "Vertex coord: " << xVal << " , " << yVal << " , " << zVal;     }}我嘗試用索引直接訪問替換for循環(及其中的條件):float xVal = *(bufferPtr + index * stride + 0);float yVal = *(bufferPtr + index * stride + 1);float zVal = *(bufferPtr + index * stride + 2);qDebug() << "Vertex coord without loop: " << xVal << " , " << yVal << " , " << zVal;但輸出日志給我不同的結果:Vertex coord:  14.574  ,  -8.236  ,  7.644Vertex coord without loop:  20.67  ,  -19.098  ,  18.536Vertex coord:  14.552  ,  -8.024  ,  7.842Vertex coord without loop:  -0.361096  ,  0.109164  ,  0.926117Vertex coord:  14.722  ,  -8.18  ,  7.842Vertex coord without loop:  20.648  ,  -19.052  ,  18.522我無法弄清楚為什么結果不同:(C ++
查看完整描述

3 回答

?
DIEA

TA貢獻1820條經驗 獲得超3個贊

你知道[]運算符嗎?你知道指針算術需要對象的大小,指針指向它嗎?你知道struct嗎?我不知道你的代碼為何如此復雜。您能否提供一些背景知識,為什么您需要通過手工制作的指針算法進行所有訪問?

查看完整回答
反對 回復 2019-06-02
  • 3 回答
  • 0 關注
  • 706 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號