954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problems with pointers

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

Fzn10
Newbie Poster
1 post since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

> #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?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
#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.

b2daj
Newbie Poster
8 posts since Aug 2006
Reputation Points: 11
Solved Threads: 0
 

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.

dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
 

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

sruthivin
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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 */
}
arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

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

sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
 

>> 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.

mike_2000_17
Posting Virtuoso
Moderator
2,139 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

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

sruthivin
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You