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>

What is ‘__FILE__’ and ‘__LINE__’?

‘__FILE__ ‘, __LINE__’ 이란 무엇인가?

로그 라이브러리를 분석하던 중, __FILE__ 과 __LINE__ 이라는 구문을 발견하고 의문을 가져 내용을 찾아보았다.
아래의 주소에서 내용을 확인할 수 있었다.

http://www.codeguru.com/forum/showthread.php?t=231043

정답은 __FILE__ 과 __LINE__ 은 전처리기(Preprocessor) 에서 지정해주는 매크로라는 것.

__FILE__ 의 경우 현재 __FILE__ macro 를 사용한 파일의 이름을 나타내주고

__LINE__ 의 경우 현재 __LINE__ macro 를 사용한 파일에서 몇 번째 줄에 위치했는지를 나타내준다.

이와 비슷한 전처리기 매크로는

  • ‘__DATE__’ -> a string literal of the form “Mmm dd yyyy”
  • ‘__TIME__’ -> a string literal of the form “hh:mm:ss”
  • ‘__TIMESTAMP__’ -> a string literal of the form “Mmm dd yyyy hh:mm:ss”
  • ‘__FUNCTION__’ -> a string literal which contains the function name (this is part of C99, the new C standard and not all C++ compilers support it)

가 있다.

아래는 __FILE__ 과 __LINE__ 을 이용한 예제와 결과이다.

#include 

int main(int argc, char** argv)
{
        printf("%s:%dn", __FILE__, __LINE__);
        return 0;
}

결과

jonathan@jonathan-laptop:~/Desktop/temp/test$ ./test
test.c:6