Hi, i have the following defined on top of the program in C

#define Mess1 "\n\rWaterflow Sensor";

in my main i have the following written:-
AsUSARTsendBytes(Mess1);

The function being called is like that
void AsUSARTsendBytes( char *bytes )

Something however is going wrong the compiler is giving the following message:-
illegal conversion between pointer types

what can i do to fix this, thanks

> #define Mess1 "\n\rWaterflow Sensor";
Well the ; at the end of this line should really have drawn a syntax error from your compiler, not a pointer convertion error.

Which leads me to suspect you've posted from memory what you think you've got, rather than copy/pasting what you've actually got.

A complete compilable example program which demonstrates the problem is far better than 3 disjointed lines which contain other problems.

> i have the following defined on top of the program in C
You might be writing in C, but does your compiler know that?
Too many people name their C programs with filenames like prog.cpp and get into all sorts of trouble as a result.

Saying which OS/Compiler you're using as well would help, since the functions you're calling are non-standard.

Did you prototype the function before calling it?
Is the prototype consistent with the definition?

#include <stdio.h>
#define DENEME "hehehehe"

void mydenemefunc(char * in) {
     puts(in);     
}

int main() {
    
    mydenemefunc(DENEME);
    
return 0;
}

this code is working for me on xp with Dev C++ complier, you should check you provided the complier a prototype of the function if its not above the main.

If the compiler isn't provided with a function definition or prototype at the point the function is called, it will say something like

warning: implicit declaration of function `foo'

and if you pass it arguments

warning: too many arguments to function `foo'

and various warnings if you use a return value incompatible with int. Nothing like "illegal conversion between pointer types". That sounds more like the function actually takes an int* for an argument or some other pointer type. Or perhaps the function parameter doesn't match the definition.

Of course, if the OP posted the error from memory they might have gotten it wrong.

The best thing to do would be to post the error exactly or better yet the code that caused it, as suggested.

what is the difference between (i) *p++ & ++*p

String literals have type "pointer to const char" and should not (and, in many circumstances) cannot be passed to function arguments of type "pointer to char"

Bad:

extern void foo(char *);

void bar()
{
    foo("Hello");   /* attempted conversion of const char * to char * */
}

Good:

extern void foo(const char *);

void bar()
{
    foo("Hello");   /* OK */
}

This thread was dead for 4 years lol. Don't post in old threads as said in the read before posting.

>> what is the difference between (i) *p++ & ++*p

++*p : reads as follows: pointer p is dereferenced to give the variable that it points to, then this variable is incremented and its final value is returned.

*p++ : reads as follows: since postfix increment has priority over dereferencing, the pointer p is incremented by one sizeof(variable_type) step, its original value is dereferenced and the variable value at the original pointer location is returned.

What is the difference between
(i) ++(*P) and (*p)++
(ii) ++*p and ++(*p)
(iii)*p++ and (*p)++
pls reply soon .Here i am waiting

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.