CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem calling function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mnv



Joined: 04 Aug 2004
Posts: 7

View user's profile Send private message

problem calling function
PostPosted: Wed Aug 04, 2004 8:37 am     Reply with quote

hi!

see the code above:

Code:


...

void myFunction(char *str1) {
    putc('x');
}

...

void main() {

    ...

    myFunction("hello");

    printf("ok");

    //end
    while (1) {
    }

}



in real the function "myFunction" is declared in an external header-file. in a former version of the function i used the parameter "str1" for printf. but i removed the printf-command because i got only trash.
as you can see the serial port monitor should show me "xhok" in this version, but it shows me "xxxxxok" instead. this means, that the function "myFunction" is executed five times although it is called only once! but when i remove "char *str1" so the function receives no more parameter, it works fine. but i need the parameter for the printf-command in the function.
so what can be the reason of that the function is executed several times and that the pointer "str1" points to invalid data and how can i get that fixed?

thank you!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 04, 2004 10:37 am     Reply with quote

Pointers to string constants are not supported. You will need to copy "Hello" to RAM and then call your function with the address of the RAM variable. The reason it is being called 5 times is that the compiler calls it for each char in your string.
Guest








PostPosted: Wed Aug 04, 2004 10:40 am     Reply with quote

hey, thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group