ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ROS determines the size of an array itself? Really

asked 2013-08-28 00:40:42 -0600

Gudjohnson gravatar image

updated 2014-01-28 17:17:45 -0600

ngrennan gravatar image

Following the ros code in ros msg format:

Ephemeris[] eph

which is equivalent of this in c:

Ephemeris *eph;

Now I have heard that ros determines itself the size of an array. One does not have to give it size.

Now for the C code inorder for me to iterate in the array I need to know the size of the array but I believe in ros, I dont.

So if I am writing a C code and I want to access the msg format and I want to iterate through the array eph, how can I do it without knowing the size of eph

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-08-28 02:17:01 -0600

dornhege gravatar image

There is a simple answer: ROS doesn't support C (in this way).

ROS messages are C++ and in that case the [] is translated to an std::vector, which has a size.

C-ports like for rosserial usually do have an additional size value.

edit flag offensive delete link more


oh cool, so I can use vector::begin() and vector::end() to navigate in the array. I will incorportate my C code into C++ then. Just one question. I know that in ROS one does not need to declare size of an array so according to your analogy, I can infer that a dynamic vector is created everytime. If this is true than it means that ROS is powerful enough to know the size of any array itself.

Gudjohnson gravatar image Gudjohnson  ( 2013-08-28 02:29:08 -0600 )edit

Yes, in C++ any [] in a message is a vector. This might be different for fixed size arrays.

dornhege gravatar image dornhege  ( 2013-08-28 02:45:52 -0600 )edit
1 gives a description of how messages are translated into python and C++.

dornhege gravatar image dornhege  ( 2013-08-28 02:47:18 -0600 )edit

Question Tools

1 follower


Asked: 2013-08-28 00:40:42 -0600

Seen: 1,977 times

Last updated: Aug 28 '13