0

I am going through source-code of a Networking Protocol. Though I understand the rules of the protocol while trying to understand the implementation seemed like not possible. The implementation used boost asio libraries. I tried to go through the docs to understand the working of the library. It helped me to understand the code a bit more, but as I move forward I still face a lot of trouble with lots of new unheard functions or data structures names used in the code. What is the fastest way I can get to know the proper purpose of a particular function or the abstract data structures implementations in C++ libraries? I was suggested to use IDE CLion. It though helped me to quickly find the declaration of the selected function in the code base and in the included header files but still, the definition was not there as it opened up .h files.

For example, I never saw ntohs function before so when I clicked on the option it opened up in.h header file and showed

extern uint16_t ntohs (uint16_t __netshort)
     __THROW __attribute__ ((__const__));

Just the declaration. Is there an easier to understand the implementation and purpose of a function other googling its name every time?

I went through the other suggestions in StackOverflow and went through articles on reading other people source code too. I couldn't find anything that's why I am here.

pergy
  • 5,285
  • 1
  • 22
  • 36
  • 3
    Generally with libraries I find it quicker to google the function name than look at source code. Doing the latter often ends up looking at hundreds of lines of template soup. – Colin Mar 10 '17 at 13:16
  • @Colin__s Often I don't find the correct definition of the function after googling it. In bigger code this serves a lot of problems. – Anuraag Gupta Mar 10 '17 at 13:18
  • I understand that you are just learning something new, however `ntohs` is one of the core functions in understanding network protocols. If this is new to you, you have a lot of reading ahead. I suggest getting some books on C and networking rather than reading code. – Richard Critten Mar 10 '17 at 13:18
  • What you are looking for is "manual pages", and that's something, that's at least in my days, was the first thing someone who starts hacking C learns, where to find it, and how to read it. If you come across a function that you don't know anything about, you look it up to see if there's a manual page for it. – Sam Varshavchik Mar 10 '17 at 13:19
  • @SamVarshavchik I did that. I thought the major functions used in the particular code where used from Boost Asio Libraries so I read up on them in its docs, but it seems other libraries were used too. I have seen myself going through entire docs just to understand one or two functions that I need to understand so I can get a grip on the working of code. I was told that I can learn on the way. – Anuraag Gupta Mar 10 '17 at 13:24
  • @RichardCritten While reading up on Boost libraries I found a lot of stuff has changed in C++11 and C++14 which I had no idea about like lambda fuctions and bind libraries. Could you please refer me some good Networking and C++ books. I haven't worked on networking libraries before but I want to understand them better. Boost asio gave me an understanding about it, but I still lack knowledge about other libraries like in.h etc. – Anuraag Gupta Mar 10 '17 at 13:29
  • There is quite a good guide to the concepts of network programming at http://beej.us/guide/bgnet/ – Colin Mar 10 '17 at 13:33
  • @SamVarshavchik Thanks a lot. I think I understood what you meant. – Anuraag Gupta Mar 10 '17 at 13:34
  • @Colin__s Thanks for the suggestion. I'll go through it. – Anuraag Gupta Mar 10 '17 at 14:02
  • @AnuraagGupta We have a compiled list of books and tutorials [here](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – πάντα ῥεῖ Mar 10 '17 at 14:36
  • @πάνταῥεῖ Thanks a lot. – Anuraag Gupta Mar 10 '17 at 14:50

0 Answers0