JaeJun LEE
JaeJun LEE

Reputation: 1334

What is the purpose of these macro definitions?

I'm working on building robot controller and I want to refer to ros::industrial_core for my project.

There are two definitions, FLOAT64, LINUXSOCKETS, and I don't know the exact functionality of FLOAT64 and LINUXSOCKETS.

Here is part of shared_types.h

#ifndef FLOAT64
typedef float shared_real;
#else
typedef double shared_real;
#endif

and here is part of simple_socket.h

#ifdef LINUXSOCKETS
#include "sys/socket.h"
#include "arpa/inet.h"
#include "string.h"
#include "unistd.h"
#endif

I have just a little intuition about them. I guess they exist for generality.

In the past, I have seen this kind of definitions but I didn't care, but now it seems that they are doing some crucial functionality.

Can you explain the functionality of this kind of definitions and how to use them, or share links to relevant articles?

Upvotes: 0

Views: 126

Answers (2)

JaeJun LEE
JaeJun LEE

Reputation: 1334

Thank you @Jonathan and @Bill.

I understood what these macro are now.

FLOAT64 and LINUXSOCKETS, both are existing for platform independence.

if your robot system uses linux socket , you have to define 'LINUXSOCKETS' before header file of simple_socket is included.

And if you have to use 'shared_real' as 8 bytes-long , you should define 'FLOAT64' before the header files of shared_real is included.

Any body wants to know more can read the developer's comment.

https://code.google.com/p/swri-ros-pkg/issues/detail?id=62

Thank you.

Upvotes: 0

Bill Lynch
Bill Lynch

Reputation: 81926

FLOAT64

When you pass data over a socket between two systems, you need to be very careful about the data types you use. It's possible that an int on one system is 2 bytes and 4 bytes on another.

This macro is attempting to make sure that the type shared_real represents an 8 byte floating point number.

LINUXSOCKETS

Presumably, this is related to some platform independent code. If we're on Linux, we should use Linux's socket implementation. But Windows probably doesn't implement the same socket protocol that Linux does. So there's probably a macro for WINSOCKETS or the like.

How does all of this work?

Normally, when you build the software, you'll run a configuration script that will generate a file named config.h (usually, but it could be named anything). This file will be different for different platforms, but will contain the correct macro definitions such that the software will work properly.

Upvotes: 2

Related Questions