| |

VerySource

 Forgot password?
 Register
Search
View: 1376|Reply: 8

Structure pointer problem

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-19 17:00:01
| Show all posts |Read mode
See a program written the following code:
lpBuf is a pointer to a structure, and he performs the following conversion on this structure pointer
(BYTE *) lpBuf

In this way, will the data be lost? If the data is lost, can you still correctly access the members of the structure using this pointer? Thank you
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-6-24 16:00:02
| Show all posts
Of course, the data will not be lost, which is equivalent to interpreting the content starting from that address in a new way.
Reply

Use magic Report

2

Threads

54

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-24 16:45:01
| Show all posts
Look how to say, if you know the size of the data
Traversal
In this way, the data cannot be said to be lost. If the member is accessed, it is impossible to directly interpret it as a member. It needs to be converted again
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-24 19:15:01
| Show all posts
Data will not be lost, pointer conversion has nothing to do with data
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-26 09:00:01
| Show all posts
Will the conversion lose data? If the data is lost, can you use this pointer to correctly access the members of the structure? Thank you
-------------------------------------------------- -----
To access its members need to be converted into the original structure pointer
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-27 01:00:01
| Show all posts
to珈蓝易拉罐

Of course, the data will not be lost, which is equivalent to interpreting the content starting from that address in a new way.
-------------------------------------------------- ------------
I don't quite understand your explanation, can you explain it?
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-27 07:30:01
| Show all posts
If you switch back when you visit, what is the significance of such conversion, or what benefits can you get? ? ?
Reply

Use magic Report

2

Threads

54

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-27 19:30:01
| Show all posts
See specific use
Sometimes to achieve a universal pointer, often converted to byte * and char *
Access data
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-29 12:30:01
| Show all posts
For example, in order to achieve byte access to the data in the structure, you can choose to convert the pointer to the structure to byte*, and then use a for to access all the data, which may be used when storing the data in the database.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list