Jump to content

Pointer Trouble...


Recommended Posts

This does not work:

   #define s8 char
  #define us8 unsigned char
  s8 i;
  for(i = 0; i < sizeof(data); i++) {
  ((us8 *)&data)[i] = 0;
  }

 

But this does:

 

   #define s8 char
  #define us8 unsigned char
  s8 i;
  us8 *p1;
  p1 = (us8 *)&data;
  for(i = 0; i < sizeof(data); i++) {
  p1[i] = 0;
  }

 

Jacob

Link to post
Share on other sites

Thanks for reportng. This is a known problem. Compiler will not apply array element operation [] to an expression that doesn't evaluate to a variable. A workaround is as you described by introducing a temporary variable that will replace the expression and applying array element operation to this variable.

 

Regards,

Pavel

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...