When I compiler my program I get this warning and when running it a runtime error.
The warning is:
128 ... [Warning] passing arg 1 of `MostraPantalla' makes pointer from integer without a cast

Dani AI

Generated

The compiler is telling you that the first argument you give to MostraPantalla is an integer value being used where a pointer is expected. That mismatch produces undefined behavior at runtime (usually a crash). Fixing the type mismatch is the route to a reliable program.

Checklist to find the problem:

  • Verify the exact prototype of MostraPantalla (the declaration/header) is visible at the call site and that its parameter types are what you expect. A wrong prototype or a forgotten declaration can mask the real type error.
  • If the function expects a pointer (for example char * or int *), pass a pointer. For a scalar variable pass its address (&x) only when the signature requires a pointer to that scalar. Passing the scalar itself (an int) will trigger the warning you saw.
  • Do not silence the warning with a cast unless you fully understand the memory layout you are forcing. Casting an integer to a pointer typically hides a real bug.

Small illustrative example:

/* expected signature */
void MostraPantalla(const char *s);

/* wrong (passes an integer) */
int index = 5;
MostraPantalla(index);   /* warning, wrong type */

/* correct */
char buf[] = "hello";
MostraPantalla(buf);     /* passes pointer to first char */

Practical debugging tips: compile with warnings enabled (-Wall -Wextra) and fix each warning. Run with AddressSanitizer (-fsanitize=address -g) or valgrind to catch the invalid memory access causing the runtime error. As noted, the & operator is appropriate only when the function expects an address; and as suggested, include both the function declaration and the call when posting code so others can point out the exact mismatch.

Recommended Answers

All 2 Replies

think you may need to use the & operator before the variable you are passing.

Chris

hey there,

you should really try to fix up any compilations first before running the program. You also need to take particular care when using pointers. If they are not used right, they can cause problems, like crashing your system, since they point to memory locations.

You also need to post your code so that we can see more clearly where the problem is.

cheers
nm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.