Pointer increament

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am using a pointer function to save three 32 bit variables value in to 3 memory location of a 32 bit controller..the following are the instruction i used

declared status_0,status_1,status_2 gloably

 

int*block0=(int*)0x00800000;

*block0=status_s0;

int*block1=(int*)0x00800001;

*block1=status_s1;

int*block2=(int*)0x00800002;

*block2=status_s2;

 

I want to know the method i used is right or wrong and there is any other way to do this by increment the pointer and how it do...i need your valuable suggestions..thank you very much

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
int *block = (int*)0x00800000;
*block=status_s0;
block++;
*block=status_s1;
block++;
*block=status_s2;
 

The memory address is in bytes, so your code will not work as you expect. If your addresses were
8000000
8000004
8000008
Then it would work as expected.

Note:you are using pointers, not pointer functions.

Last Edited: Fri. Apr 7, 2017 - 06:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you sir,, thanks for your reply

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Why on earth don't you just declare:

Int *block = (int *) 0x80000000;

then:

block[0] = status_s0;
block[1] = status_s1;
etc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

extern int blocks[3];

Assign the symbol blocks with the linker.
 

Iluvatar is the better part of Valar.