Save hex address of a int32 (savepos)

how can i save hex address?

for example, i have a int32

int32 UncompressedSize;

how can i save position of UncompressedSize block?
Last edited on
Conventionally, the address of something is saved in a pointer:
1
2
int x;
int* pointer = &x; // the address of x is saved in this pointer. 
I think you are confused a little.

how can i save position of UncompressedSize block?
no clue. that does not appear in anything you showed us, nor is it anything in standard C++. What are you talking about?

hex ... there are 2 answers.
1) a number is a number. the computer stores them in binary bits, or electrically live or dead wires, as you prefer.
2) you can print numbers in many formats, one of which is hex. Is that what you want?


offset of UncompressedSize block, that is what i want to print
I am going to guess that you have some kind of data object.

In that object are many values.

One of those values is called the "UncompressedSize".

Is this correct?

If so, what data? What object? What are you talking about? Do you know this is a C++ programming forum? We answer C++ questions.
std::cout << &UncompressedSize
If that doesn't do what you want, then I'm sorry, but you'll need to rephrase your question.

Side note, if you're hoping to save that address such that it can be loaded at a future date, then you're likely doing something wrong.

-Albatross
Similar to others' responses, I am also confused as to what you want. The 2 possibilities that I can see are basically the options @Repeater mentioned. Are either of these what you want?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>
#include <stdint.h>


struct MyStruct
{
	int stuff;
	int32_t UncompressedSize;
};

int main()
{
	int32_t UncompressedSize;
	MyStruct object;

	std::cout << "Address: " << std::hex << &UncompressedSize << std::endl;
	char* objAddr = static_cast<char*>((void*)&object);
	char* memberAddr =  static_cast<char*>((void*)&(object.UncompressedSize));
	std::cout << "Offset into object: " << (memberAddr - objAddr)  << std::endl;
	
}
look, let me be clear

i want to read a int32 block that called it UncompressedSize
and i want to save location of UncompressedSize block that i can able to find it in hex editor, that is why i need to do this, i want to save hex-address of UncompressedSize to search in hex editor

sorry for my bad english
Last edited on
Oh! Are you reading into UncompressedSize from a binary file?

http://www.cplusplus.com/reference/istream/istream/tellg/ might be what you're looking for (call immediately after reading into UncompressedSize).

-Albatross
Topic archived. No new replies allowed.