R
ram
In this complete tiny example, version one of an expression fails
----> theChar = *(currentMessage + characterNumber);
while my workaround expression version two succeeds.
----> theChar = (message[messageNumber])[characterNumber];
Both versions are fine on one C compiler and target but on another
version one fails. My understanding is that there should be no practical
difference, i.e. both should work.
- rob
# include <stdio.h>
const unsigned char *message[3] = {
"one message",
"second message",
"third and last maessage",
};
unsigned char *currentMessage;
unsigned char theChar;
unsigned char messageNumber, characterNumber;
unsigned char result;
int main(void)
{
result = 0;
/* version one */
currentMessage = (unsigned char *) message[1];
characterNumber = 2;
theChar = *(currentMessage + characterNumber);
if ('c' == theChar)
result |= 1;
/* version two */
messageNumber = 1;
characterNumber = 2;
theChar = (message[messageNumber])[characterNumber];
if ('c' == theChar)
result |= 2;
/* report */
printf("\n%d\n", result); /* should be 3, but is in fact 2 */
}
----> theChar = *(currentMessage + characterNumber);
while my workaround expression version two succeeds.
----> theChar = (message[messageNumber])[characterNumber];
Both versions are fine on one C compiler and target but on another
version one fails. My understanding is that there should be no practical
difference, i.e. both should work.
- rob
# include <stdio.h>
const unsigned char *message[3] = {
"one message",
"second message",
"third and last maessage",
};
unsigned char *currentMessage;
unsigned char theChar;
unsigned char messageNumber, characterNumber;
unsigned char result;
int main(void)
{
result = 0;
/* version one */
currentMessage = (unsigned char *) message[1];
characterNumber = 2;
theChar = *(currentMessage + characterNumber);
if ('c' == theChar)
result |= 1;
/* version two */
messageNumber = 1;
characterNumber = 2;
theChar = (message[messageNumber])[characterNumber];
if ('c' == theChar)
result |= 2;
/* report */
printf("\n%d\n", result); /* should be 3, but is in fact 2 */
}