Warning on static function

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi at all,

   

I'm working with PSoC Creator and I have a little problem; in my header file I have declared a static function that I have defined and used in the relative source file, but when I compile the code, appears this warning 

   

'sht1x_writeByte' declared 'static' but never defined [-Wunused-function]

   

I really dont' know where is the problem because the function is defined and used...please, could anyone tell me what's wrong ?

   

regards

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

Sounds a bit like a typo, but that's a guess. Best will be to post your complete project. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob

0 Likes
markgsaunders
Employee
Employee
50 sign-ins 10 solutions authored 5 solutions authored

Are you sure you did not include the header in more than one source file?

   

-- Mark.

0 Likes
SuMa_296631
Level 5
Level 5
50 replies posted 25 replies posted 10 replies posted

 Why are you placing a static function declaraction into a header?

   

Typically a header is used by multiple source files so they know that there is a suitably named function that they can use. (Often they have an 'extern' part of their declaration as well.)

   

However 'static' tells the C compiler that this funciton is not visible outside the source file.

   

Therefore, if you are using the header in a source file that does NOT define the function, then the compiler will complain.

   

Susan

0 Likes
Anonymous
Not applicable

First of all, thank you for welcome; I read all your posts and I find the last very interesting, in fact I did not realize this issue...now I'll declare my static function only in the source file. Thank you very much for all 😉

0 Likes