size_t warning. int’ is smaller than type ‘unsigned long

사내 HP-UX 서버에서 컴파일을 하다, 아래의 Warning 이 나왔다.

Warning (suggestion) 887: “SharedMemory.cpp”, line 711 # Type ‘int’ is smaller than type ‘unsigned long’, unwanted widening in value may result.        memset(szTotalHexData, 0x00, (iSize * 3) + 1);                                      ^^^^^^^^^^^^^^  

이유인즉, unsigned long type 이 와야 하는데, int type 이 왔다는 것.

이상할 것이 없어서 memset man 페이지를 확인해 보았다.

      void *memset(void *s, int c, size_t n);

결론은, 저 size_t 의 type. 그냥 int 형 타입인 줄 알았는데, 그게 아니었다. unsigned long type 이었다.

혹시나 HP-UX aCC 에서만 적용되는건 아닌가 싶어서 g++ 에서도 찾아보았다.

확인 결과, 둘 다 unsigned long type 이 맞았다.

g++-4.7.3

#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t;

aCC: HP ANSI C++ B3910B A.03.37

#include <sys/stdsyms.h>

#ifndef _SIZE_T_INCLUDED
#       define _SIZE_T_INCLUDED

#       ifndef _SIZE_T
#               define _SIZE_T
_NAMESPACE_STD_START
                        typedef unsigned long size_t;
_NAMESPACE_STD_END
#       endif /** _SIZE_T **/

#endif /** _SIZE_T_INCLUDED **/

 

 

 

 

“/opt/aCC/include_std/utility”, line 99: error #2070: incomplete type is not allowed

HP 장비에서 aCC 로 컴파일을 하던도중 아래의 에러가 발생했다.

“/opt/aCC/include_std/utility”, line 99: error #2070: incomplete type is not
allowed
first_type  first;
^
detected during:
instantiation of class “std::pair<_TypeT, _TypeU> [with
_TypeT=const std::string, _TypeU=char *]” at line 97 of
“/opt/aCC/include_std/rw/tree”
instantiation of class “__rw::__rw_rb_tree_node<_Alloc, _Val,
_Key, _KeyOf> [with
_Alloc=std::allocator<std::pair<const std::string, char
*>>, _Val=std::pair<const std::string, char *>,
_Key=std::string,
_KeyOf=__rw::__select1st<std::pair<const std::string,
char *>, std::string>]” at line 282 of
“/opt/aCC/include_std/rw/tree”
instantiation of class “__rw::__rb_tree<_Key, _Val, _KeyOf, _Comp,
_Alloc> [with _Key=std::string, _Val=std::pair<const
std::string, char *>,
_KeyOf=__rw::__select1st<std::pair<const std::string,
char *>, std::string>, _Comp=std::less<std::string>,
_Alloc=std::allocator<std::pair<const std::string, char
*>>]” at line 102 of “/opt/aCC/include_std/map”
instantiation of class “std::map<_Key, _TypeT, _Compare,
_Allocator> [with _Key=std::string, _TypeT=char *,
_Compare=std::less<std::string>,
_Allocator=std::allocator<std::pair<const std::string,
char *>>]” at line 54 of “LocalRepository.h”

이유인즉, HP 컴파일러 aCC 가 버전 6로 넘어오면서 기존(aCC version 5)에서 허용했던 C++ 타입에 대한 처리를 더이상 허용하지 않으면서 발생한 문제였다.

관련링크 : http://h21007.www2.hp.com/portal/site/dspp/menuitem.863c3e4cbcdc3f3515b49c108973a801/?ciid=2708d7c682f02110d7c682f02110275d6e10RCRD#_iso-39._acc6_detects_instantiation_

공식 문서내용은 다음과 같다.

ISO-39. aCC6 detects instantiation conflicts earlier (2403)

Points of instantiation differ for member functions, so reporting of instantiation conflicts can differ. This is simply a behavior difference, and not a compatibility issue. However, the following code snippet illustrates an incompatibility in the use of repeated const keywords, which aCC5 allows and aCC6 does not. To fix this code, don’t instantiate the template with a const int; simply use int:

template <class T>
struct S {
void foo(T *i) {}
void foo(const T *i) {}
};
int main() {
int i = 5;
#ifdef WORKS_IN_BOTH
S<int> s;
#else
S<const int> s;
#endif
return 0;
}

내용인즉, C++ 에서 template 사용시 const 를 사용하지 말라는 뜻이다.

위의 에러에서 문제가 해당 라인(line 54 of “LocalRepository.h”)을 찾아가보니 아래와 같이 선언되있었다.

map<string, char*> m_mapStringMainData;

뭔가 이상했다. map 선언 중, 어디에도 const 는 있지 않았다. 어찌된 일일까.

한참을 헤매고 주위에 도움을 구해서 찾아낸 정답은 정말 엉뚱한 곳에 있었다.
바로 iostream 였다.

다음의 라인을 추가하여 깔끔히 문제를 해결할 수 있었다.

#include <iostream>

왜 이런 문제가 생긴 것일까? 조금 더 질문을 해본 결과 한가지 재미있는 사실을 알 수 있었다.
이전 버전의 aCC 에서는 iostream 을 include 하면 또 안된다는 것..

아직 배워야할 것이 많다..

HP-UX Hardwar/OS support & CPU/OS support

Unix 는 장비도 다양하고,  버전도 다양하다.

HP UX에 관련한 Hardware/OS support 에 관한 리스트는 아래의 링크에서 찾을 수 있다.

http://www.hp.com/go/hpuxservermatrix

그리고 다른 HP UX 에 관한 CPU/OS support에 관한 내용은 아래의 링크에서 찾을 수 있다.

http://search.cpan.org/~rjbs/perl-5.12.3/README.hpux