1

I'm doing the following:

static uint32 myReadValue;
static uint32 myNewValue;

DoRead(10, &myReadValue);

myNewValue = (uint32)(&myReadValue) | (3 << 8);

whereby

void DoRead(SomeEnumType, void * Ptr)
{
    // some functionality
}

The compiler gives me the messages:

"conversion of integer to pointer at assignment" on the assignment of "myNewValue" 

I don't see exactly what I'm doing wrong there. Any idea?

chqrlie
  • 131,814
  • 10
  • 121
  • 189
JohnDoe
  • 825
  • 1
  • 13
  • 31

1 Answers1

2

(uint32)(&myReadValue) is a conversion to uint32 of a pointer to myReadValue, not the other way around and this conversion does not happen at assignment... There is something you are not telling us. Post compilable code that produces the proble.

The cast is useless anyway, you probably should use this instead:

myNewValue = myReadValue | (3 << 8);
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • Oh correct. Sorry, basically the problem was at the variable declaration. They were originally inside a struct and not like i mentioned in this example. This caused a misinterpreting from my side. – JohnDoe Dec 09 '20 at 10:05
  • How exactly is `(uint32)(&myReadValue)` a conversion of integer _to_ pointer at _assignment_? It's rather a conversion from pointer to integer by cast. Sensible compilers give warning about cast to a potentially too smal integer type to hold the pointer address, but not the error posted in the question. So this doesn't answer the question (which likely cannot be answered in its current form). – Lundin Dec 09 '20 at 10:25
  • @Lundin: I agree the warning is confusing and possibly refers to some other code. There is a conversion, but from pointer to integer and there is an assignment, but after evaluating an arithmetic operator... so this warning is either irrelevant or misrepresented. – chqrlie Dec 09 '20 at 20:19