# Double quotes vs angled brackets for "ros/ros.h"

I am unclear why "ros/ros.h" isn't in angled brackets like <std_msgs>. They both come from ROS, don't they and are installed at the same time?

#include "ros/ros.h"
#include "simple_arm/GoToPosition.h"
#include <std_msgs/Float64.h>


EDIT for clarification:

I understand the convention in C++ of local vs system headers and the search path, but what is local of ros/ros.h? I didn't write it and it came with the installation. The same with std_msgs/Float64.h.

edit retag close merge delete

Sort by » oldest newest most voted

As pointed out elsewhere, this is a C/C++ question rather than a ROS question. The difference between the two styles of #include specify different directory search strategies:

• Using angle brackets (#include <iostream>) asks the C/C++ preprocessor to look for the given path only in directories in the configured include search path. (In particular, the current directory is not searched.)
• Using double quotes (#include "iostream") asks the C/C++ preprocessor to look for the given path relative to the current directory and then try directories in the configured include search path. The standards are specific about this, so you can think of using double-quotes as searching a superset of locations.

The default include search path is set by the compiler, and can be altered by environment variables or command-line options (-I, for example). The C/C++ standards use more vague phrasing like "an implementation-defined manner" for the include search path. See your compiler's documentation for specifics. The default include search path differs, typically, between C and C++ compiles. (So using g++ rather than gcc on the command line will give different results, for example.)

It's conventional to use angle brackets for includes provided by the system or libraries and double-quotes for your source code. (But the distinction between "your source" and "libraries" also depends on how you've set up your project.) It seems to me more conventional to use #include <ros/ros.h> rather than double-quotes.

more

1

Please note that AFAIK, what you describe is not actually a standard, or prescribed behaviour, but a convention (which admittedly many (all?) popular compilers adhere to).

( 2020-04-08 12:55:00 -0500 )edit
1

Yes, you're correct (though, as you mention, I don't know of a popular compile for C/C++ that doesn't do it that way). The standard says that everything using angle brackets is implementation-defined, and that using double-quotes it first tries the path using the current directory and then uses the angle-bracket method (whatever it is).

( 2020-04-08 15:29:04 -0500 )edit

Without more context, there would be no good reason to #include the ros/ros.h header with quotes and the other(s) with <>.

Both will work.

A weak convention however is to use quotes for "local headers" and <> for headers from other libraries.

more

1

Note: this is not a ROS question, but a general C++ one.

( 2020-04-08 04:08:59 -0500 )edit

It is a ROS question. I clarified in the question with an edit.

( 2020-04-08 05:36:44 -0500 )edit

I'm not sure how your edit changes the question.

"local to ros/ros.h" does not really make sense to me.

My answer would remain the same: both quotes and <> would eventually result in the same header being included, unless you happen to have another ros directory in the directory which stores the .cpp (or whichever file is #includeing ros/ros.h) and that directory also contains a ros.h.

But there is no actual C++ standard which requires preprocessors/compilers to follow this convention, so it's implementation defined.

Perhaps, if you could tell us where you found this code, it would provide more context and perhaps we could then say something more about why it was done with quotes in this case.

( 2020-04-08 06:18:04 -0500 )edit

The code is from an example from an old course. I think they made a mistake and weren't consistent with the angled brackets. By local, I meant that it was a file written by me and not something like <vector> that comes with C++.

( 2020-04-08 06:53:22 -0500 )edit

There are style guides which prefer the use of quotes over <> for certain types of commits.

But without knowing whether the course authors / developers followed any of those, it'll be difficult to determine whether that would be the (main) reason here.

( 2020-04-08 07:01:33 -0500 )edit