C ++-通过添加字节整数向前移动char指针是否合法/建议? [英] C++ - Is moving char pointer forward by adding integer of bytes legal/recommended?

查看:111
本文介绍了C ++-通过添加字节整数向前移动char指针是否合法/建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些方法来使指针指向压缩档案中文件的开头.

I am looking for some ways to advance pointers to the beginning of files in compressed archives.

我有一个字符指针,指向已读入内存的文件的开头.存档目录包含每个文件的偏移量.是否合法/建议说:

I have a character pointer to the beginning of the file that has been read into memory. The archive directory contains the offsets of each file. Is it legal/recommended to say:

char* beginning; //Imagine this is assigned to the beginning of the file in memory
int file1OffsetBytes = 1000; // Imagine the first file is 1000 bytes into the file

char* file1 = beginning + file1OffsetBytes;

这是个坏主意吗?还有另一种方法吗?

Is this a bad idea? What is another way to do this?

推荐答案

很好.您只需要注意越界跳跃... 还有一件事:这是通常用于内存缓冲区偏移的size_tssize_t类型.

that is quite Ok. You only have to take care about out of bounds jumps... and one more thing: here is an size_t or ssize_t type usually used for memory buffers offset.

这篇关于C ++-通过添加字节整数向前移动char指针是否合法/建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆