Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use -inl.h files?

I just noted this item in the Google C++ Coding Style Guide - and I don't quite get it.

If I put an inline method or function in a file other than the header included by other files, it will not be a method of the class; and it will only be usable to bits of code which include it. So why even have such -inl.h files at all?

Also, why do we even want to inline long functions anyways? (i.e. other than in the case of templates, when we have to put the code in the header files for instantiation)

like image 424
einpoklum Avatar asked Jul 17 '13 11:07

einpoklum


People also ask

What is the main reason to use files?

A file is a tool used to remove fine amounts of material from a workpiece. It is common in woodworking, metalworking, and other similar trade and hobby tasks.

What is file and when it is used?

A file is the common storage unit in a computer, and all programs and data are "written" into a file and "read" from a file. A folder holds one or more files, and a folder can be empty until it is filled. A folder can also contain other folders, and there can be many levels of folders within folders.

When should we use file sharing?

File sharing allows several people to use the same file data. Some users may be able to create and modify files depending on access permissions, while others may only have read access or even no access.

When should I use File Explorer?

File Explorer is the file management application used by Windows operating systems to browse folders and files. It provides a graphical interface for the user to navigate and access the files stored in the computer. The main way to access the File Explorer is by clicking the folder icon in the Taskbar.


1 Answers

I just noted this item in the Google C++ Coding Style Guide - and I don't quite get it.

Do take that guide with a pinch of salt. Many of the guidelines are intended to help interact with Google's legacy codebase, and aren't particularly good advice for general C++ development.

So why even have such -inl.h files at all?

There's no particularly good reason; I don't do that myself. Some people like them because it minimises the amount of stuff in the main header file, which users of the header generally want to read, and separates out the implementation details, which they generally don't care about.

Also, why do we even want to inline long functions anyways?

Sometimes, we must: template definitions must be available in any translation unit that instantiates the template, so they (usually) need to be in headers.

Sometimes, we want to: by implementing a function inline in a header, we don't have to worry about building and linking a separate translation unit for it. This can make it more convenient to distribute a library; possibly at the cost of longer build times.

like image 171
Mike Seymour Avatar answered Oct 12 '22 23:10

Mike Seymour