2

I have a c program (not c++) and it has a value declared as

int msgNumber = 5555

I also have an external assembler routine that the above C program calls and I want to pass it the address of the msgNumber value in the C program so the assembler program can update the value and then return to the calling C program

Can anyone explain to me how to do this please?

What have I tried,

I tried this:

int msgNumber = 5555;
        VSHRTMSE(*msgNumber);      /*Ask for first or next msg from msg table entry */

the complier did not care for that

ERROR CCN3018 src/c/VSHXYS.c:1480  Operand of indirection operator must be a pointer expression.
CCN0793(I) Compilation failed for file src/c/VSHXYZ.c.  Object file not created.
FSUM8226 make: Error code 12

I am not a C programmer, and am beating my head against the wall trying to figure this out.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 7
    You might have mixed the dereference operator `*` with the pointer-to operator `&`. If you need to program in an unknown language, please make some effort to learn the basics first. – Some programmer dude Aug 01 '23 at 16:06
  • 2
    Some terminology: `msgNumber` is a *variable*, not a value. – Ian Abbott Aug 01 '23 at 16:17
  • 1
    Welcome to Stack Overflow! Using `&` instead of `*` should indeed likely fix the issue for you. For completeness, you should also post the declaration of `VSHRTMSE` so we can check if there is anything wrong with that. – fuz Aug 01 '23 at 16:42
  • Surely there must be an existing Q&A that explains that `&` is the address-of operator. The closest I found was [Why use address of variable to change the value of a variable?](https://stackoverflow.com/q/55583918) and [Passing by reference in C](https://stackoverflow.com/q/2229498). Also [Getting the address of a variable](https://stackoverflow.com/q/24044294) (many "take address" / "get address" questions were about passing the address to `printf` for some reason. I guess people were doing that instead of using a debugger to satisfy curiosity about "low-level" stuff.) – Peter Cordes Aug 01 '23 at 19:59

1 Answers1

1

The comments really have the answer. To formalize it here you are using the dereference operator * which is how you refer to the value pointed to by a pointer.

int msgNumber holds the value of integer you want to pass and not the address of an integer.

What you need to do is to pass the address which would be done like this using the pointer-to operator:

  int msgNumber = 5555;
  VSHRTMSE(&msgNumber);      /*Ask for first or next msg from msg table entry */
Hogstrom
  • 3,581
  • 2
  • 9
  • 25