This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding all necessary .h files to every .c file

Hello there, I am already guessing that by the question alone it seems like what i'm asking is silly or wrong but I have no formal education here so I will need some help.

I have done all the tutorials posted, (advertising, services, characterisitcs, ble_uart, etc..) on my nrf51-dk but now I am on the ble_app_template to try and make my custom service and characteristics but I just can't seem to understand the structure of it all.

Why is it that main.c and the other tutorials .c files (like our_service.c) have so many .h files beneath it? are they all necessary or are some just to be sure? are these "packs" that are installed or are they something else? Whenever I make a .c file to make a service how do i get all the correct .h files the go beneath it so i can begin to follow the tutorials on how to create characteristics for my particular project?

So I guess im asking for an explanation as well as a little instruction. The nAN-36 is helpful but a its thing like this that i don't understand that are a big issue for me continuing. And answer is helpful, thank you

Parents
  • Each time you want to use a function that someone else has written, you need to #include a file where that function is defined. Otherwise, the compiler won't know which function you're talking about. In general, this means that if you're trying to use e.g. PWM code, you need to #include the relevant PWM header. If you're using code from lots of different modules, like main.c does, then you'll need a lot of header files.

    Code won't compile if you're missing a header file include, but it will compile if you have an extra header file included. This means that over time you may end up with extra #includes at the top of your file, as you may have added them to allow you to use functions you no longer use. So sometimes there can be non-essential #includes.

    I'm not sure what you mean by "import files as a package", or if there's a better way to answer your question. Is there another programming language that you know, so that I could make an analogy to that?

  • Just try it! You'll know if you need to include a header because it won't compile.

Reply Children
No Data
Related