Where are C types defined?

I am trying to find the header file where this function is defined:

sendNTPpacket(

This is from one of the Ethernet examples in arduino.

I also want to know what other similar functions are defined.

If the example is the “Udp NTP Client”; it has 3 include files which in themselves have further include files. It can get quite frustrating trying to find exactly where a function is declared. I searched for some time and could not find it.
The code complies correctly for me so it must be declared somewhere; but I have not tested it as I dont have an Ethernet shield.

I used

to get the network time for an Adafruit HUZZAH ESP8266 board. This code redefines sendNTPpacket() so you can see what it is doing.

Regards
Jim

2 Likes

You could try

find /usr/include/ -type f -exec grep -n sendNTPpacket {} \; -print
1 Like

A very reasonable want, and C/C++ is designed for this sort of discoverability - “header files” list related functions so you can see what’s supported. This is so powerful that most editors will automatically parse these header files and list the options as you type.

Alas, Arduino does none of this. It deliberately hides this detail to simplify the experience. Congratulations, you have out-grown Arduino!

As the answers so far suggest, your options are:

  1. Stay within the Arduino sandbox and use vendor supplied example code and documentation to figure out what you want to do.
  2. Search your hard drive for the header file. Cross your fingers.
  3. Or, move beyond Arduino. Unfortunately there’s not a single, gentle transition. This site does a great job of summarising the best options: 16 Arduino IDE alternative to start programming

By the way, your thread title has a number of mistakes. I know it’s so hard to know how to ask a question when you don’t know the answer! Here’s some tips for next time:

  • “C”. Arduino is actually built on C++. While most C code will work in C++, the reverse is not true. This is really a question about Arduino libraries. Under the hood they are C++ libraries, but the question of “where” is Arduino specific. It’s definitely not a C question.
  • “types”. sendNTPpacket is a function, not a type.
  • “defined”. The definition of a function is the code that defines what the function does. You’re looking for the declaration which simply gives the name and parameters of the function and generally has comments that explain what it’s for. The definition is not always available - it might be pre-compiled into object code. If it is available in a cpp file, it might be difficult to read. The declaration on the other hand is always available, usually in a header file (.h). Usually it’s easy to read because it is designed to be read by the user.
1 Like