\hypertarget{convert_8h}{\section{opal/util/convert.h File Reference}
\label{convert_8h}\index{opal/util/convert.\+h@{opal/util/convert.\+h}}
}


This file will hopefully not last long in the tree, but it's unfortunately necessary for now.  


{\ttfamily \#include \char`\"{}opal\+\_\+config.\+h\char`\"{}}\\*
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
B\+E\+G\+I\+N\+\_\+\+C\+\_\+\+D\+E\+C\+L\+S O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int \hyperlink{convert_8h_a0a6f5df8880f821a66487cfa8425f463}{opal\+\_\+size2int} (size\+\_\+t in, int $\ast$out, bool want\+\_\+check) \+\_\+\+\_\+opal\+\_\+attribute\+\_\+nonnull\+\_\+\+\_\+(2)
\begin{DoxyCompactList}\small\item\em Convert a size\+\_\+t to an int. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
This file will hopefully not last long in the tree, but it's unfortunately necessary for now. 

There are multiple places in the code base where we need to safely convert from a size\+\_\+t to an int. However, on some platforms, sizeof(size\+\_\+t) is larger than sizeof(int), so casting from size\+\_\+t -\/$>$ int will result in a compiler warning and potentially data truncation.

But, unfortunately, we still need to do it. But we definitely do not want compiler warnings. So when sizeof(size\+\_\+t)$>$sizeof(int), the solution is the treat the size\+\_\+t value like an array and dereference the appropriate nibble and cast that to an int (which accounts for both big and little endian machines).

Most places in the code where this casting must occur are because collision of A\+P\+Is (e.\+g., one A\+P\+I requires a size\+\_\+t and another A\+P\+I requires an int. And in most places, we're not going to overflow the int when casting down into it (e.\+g., it's the result of a strlen, or the length of the buffer in an ompi\+\_\+buffer\+\_\+t -- if that buffer is larger than M\+A\+X\+\_\+\+I\+N\+T, we've got other problems!).

B\+U\+T -- the whole premise of casting down to an int is dangerous. So we provide extra protection here to detect overflow situations and print out appropriate warnings. So if this situation ever occurs, we'll still overflow, but we'll have a good indication that it's happening, and where. 

\subsection{Function Documentation}
\hypertarget{convert_8h_a0a6f5df8880f821a66487cfa8425f463}{\index{convert.\+h@{convert.\+h}!opal\+\_\+size2int@{opal\+\_\+size2int}}
\index{opal\+\_\+size2int@{opal\+\_\+size2int}!convert.\+h@{convert.\+h}}
\subsubsection[{opal\+\_\+size2int}]{\setlength{\rightskip}{0pt plus 5cm}B\+E\+G\+I\+N\+\_\+\+C\+\_\+\+D\+E\+C\+L\+S O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int opal\+\_\+size2int (
\begin{DoxyParamCaption}
\item[{size\+\_\+t}]{in, }
\item[{int $\ast$}]{out, }
\item[{bool}]{want\+\_\+check}
\end{DoxyParamCaption}
)}}\label{convert_8h_a0a6f5df8880f821a66487cfa8425f463}


Convert a size\+\_\+t to an int. 


\begin{DoxyParams}{Parameters}
{\em in} & The size\+\_\+t value to be converted \\
\hline
{\em out} & The output int value. \\
\hline
{\em want\+\_\+check} & Whether to check for truncation or not\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
O\+P\+A\+L\+\_\+\+S\+U\+C\+E\+S\+S If all went well 

O\+P\+A\+L\+\_\+\+N\+O\+T\+\_\+\+S\+U\+P\+P\+O\+R\+T\+E\+D if the size\+\_\+t value was truncated
\end{DoxyReturn}
The conversion will always occur. However, if the size\+\_\+t value was truncated (i.\+e., sizeof(size\+\_\+t) $>$ sizeof(int), and the cast down to the int actually changed the value), O\+P\+A\+L\+\_\+\+N\+O\+T\+\_\+\+S\+U\+P\+P\+O\+R\+T\+E\+D will be returned.

On platforms where sizeof(size\+\_\+t) $<$= sizeof(int), this function will aways return O\+P\+A\+L\+\_\+\+S\+U\+C\+C\+E\+S\+S. 