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 **/

 

 

 

 

C++ Int, char, double, 등등의 자료형 사이즈..

C++ 에서의 자료형의 크기는 컴파일러에 따라 좌우된다고 알고 있었다.

틀린 내용은 아니였지만.. 정확하지는 않았다.

아래 링크에서 정확한 내용을 알 수 있었다.

정확하게는… 크기는 정해져 있지 않지만, C++ 표준에서 지정하는 최소 사이즈가 있다는 것이다.

The C++ standard does not specify the size of integral types in bytes, but it specifies minimum ranges they must be able to hold. You can infer minimum size in bits from the required range and the value of CHAR_BIT macro, that defines the number of bits in a byte (in all but the most obscure platforms it’s 8).

출처 : http://stackoverflow.com/questions/589575/size-of-int-long-etc

메시지 큐 타입 관련.. msgsnd

 

IPC 를 위해 MessageQueue 를 사용해야 했다.

그런데 문제는 msgsnd 시스템 함수를 통해 데이터를 보낼려고 하는데 자꾸 에러가 나는것..

[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,232]<ERR>Queue Create Failed. Queue Already Created. Id[4653059]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,217]<ERR>Queue Create Failed. Invalid Queue Key[-1]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,217]<ERR>Queue Create Failed. Invalid Queue Key[1215752192]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,224]<ERR>Queue Create Failed. Invalid Queue Size!! Size[1215752192]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,283][3]<INF>Queue Create Success!! Input Key[494949], Size[10000] => Created Key[494949], Id[4685827], Size[10000]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,283][3]<INF>Queue Create Success!! Input Key[494949], Size[10000] => Created Key[494949], Id[4718595], Size[10000]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,84][3]<INF>Queue Write. Id[4718595],Type[0],Buf[THIS IS TEST],Size[5]
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/nxlib/common/queue.c,195][1]<WriteQueue>msgsnd error:-1, 22(Invalid argument)
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/nxlib/common/queue.c,196][1]<WriteQueue>Info Id[4718595], Type[0], Data[THIS ], Len[5], Ret[-1]
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,88]<ERR>Queue Write Failed!

로그 내용이다.. 문제가 생기는 부분은 마지막 부분의 <WriteQueue>msgsnd error:-1, 22(Invalid argument) 부분.

전혀 문제가 발생할 부분이 없는데 문제가 발생해서 한참을 헤매다가 겨우답을 찾았다.

 

msgsnd 의 맨페이지에서 답을 찾을 수 있었다.

DESCRIPTION
The  msgsnd()  and  msgrcv() system calls are used, respectively, to send messages to, and receive messages from, a message queue.  The calling process must have write permission on the
message queue in order to send a message, and read permission to receive a message.

The msgp argument is a pointer to caller-defined structure of the following general form:

struct msgbuf {
long mtype;       /* message type, must be > 0 */
char mtext[1];    /* message data */
};

The mtext field is an array (or other structure) whose size is specified by msgsz, a nonnegative integer value.  Messages of zero length (i.e., no mtext field) are permitted.  The mtype
field must have a strictly positive integer value.  This value can be used by the receiving process for message selection (see the description of msgrcv() below).

문제는 메시지 큐 타입을 ‘0’으로 하고 msgsnd를 호출 했던 것…

맨페이지에 명확하게 적혀 있었다.”/* message type, must be > 0 */” …. 아..;;

 

큐 타입을 1로 하고 호출하자 정상 작동 되었다.

error: ‘EOF’ was not declared in this scope

오픈소스 컴파일 중, 다음과 같은 에러 메시지를 발견했다.

error: ‘EOF’ was not declared in this scope

make[1]: Entering directory `/home/jonathan/workspace/13.CIDS/CIDSSip/SipLibrary/resiprocate-1.6/rutil’
g++         -march=i686 -D_REENTRANT  -g  -Wall  -I.. -I../build/../contrib/ares -DOS_MAJOR_VER=2 -DOS_MINOR_VER=6 -DOS_POINT_VER=38-13-generic-pae -DOS_PATCH_VER=0 -DRESIP_OSTYPE_LINUX -DRESIP_ARCH_I686 -DRESIP_LARCH_IA32 -DRESIP_TOOLCHAIN_GNU -DUSE_ARES -c -o obj.debug.Linux.i686/SysLogBuf.o SysLogBuf.cxx
SysLogBuf.cxx: In member function ‘virtual int resip::SysLogBuf::overflow(int)’:
SysLogBuf.cxx:39:13: error: ‘EOF’ was not declared in this scope
make[1]: *** [obj.debug.Linux.i686/SysLogBuf.o] Error 1
make[1]: Leaving directory `/home/jonathan/workspace/13.CIDS/CIDSSip/SipLibrary/resiprocate-1.6/rutil’
make: *** [rutil] Error 2

이에 대한 해결법은 아래의 링크에서 찾을 수 있었다.

http://code.google.com/p/o3d/issues/detail?id=87

문제 해결은 간단하다. 해당 소스 파일에 아래의 헤더파일을 추가하도록 명시해주면 된다.

#include <cstdio>