Skip to content

Use memcpy instead of *(int)*& #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions beginners-tutorials/tutorial-5-a-textured-cube/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ if ( header[0]!='B' || header[1]!='M' ){
Now we can read the size of the image, the location of the data in the file, etc :

``` cpp
// add to standard headers
#include <string.h>

// Read ints from the byte array
dataPos = *(int*)&(header[0x0A]);
imageSize = *(int*)&(header[0x22]);
width = *(int*)&(header[0x12]);
height = *(int*)&(header[0x16]);
memcpy(&dataPos, header + 0xA, sizeof dataPos);
memcpy(&imageSize, header + 0x22, sizeof imageSize);
memcpy(&width, header + 0x12, sizeof width);
memcpy(&height, header + 0x16, sizeof height);
```

We have to make up some info if it's missing :
Expand Down