'프로그래밍'에 해당되는 글 45건

  1. 2021.12.02 c++ int 형 타입 정리(32bit, 64bit, MAX, MIN)
  2. 2021.12.01 std::lock_guard, std::unique_lock 에서 lock, unlock 호출 시점 확인 하기
  3. 2021.11.30 데드락이 발생하는 케이스
  4. 2021.11.30 ubuntu c++ 맨페이지 설치
  5. 2021.11.26 shell script 에서 ++
  6. 2021.11.24 Lognote 0.1.6 - Android logcat viewer
  7. 2021.10.08 Lognote 0.1.4 - Android logcat viewer
  8. 2021.09.01 Lognote 0.1.1 - Android logcat viewer
  9. 2021.03.12 개발자...
  10. 2021.02.16 int 를 hex string 으로 변환

c++ int 형 타입 정리(32bit, 64bit, MAX, MIN)

프로그래밍/c,c++ 2021. 12. 2. 17:35
반응형

int 형 타입은 32bit, 64bit 에 따라, OS 에 따라 달라질수 있다.

가능하면 int32_t 등 bit 수를 명시하는 방법으로 코딩 하는 것도 괜찮은 방법.

32 bit linux 64 bit linux
char                          1 bytes
unsigned char                 1 bytes
-----------------------------------------------
short                         2 bytes
unsigned short                2 bytes
-----------------------------------------------
int                           4 bytes
unsigned int                  4 bytes
-----------------------------------------------
long                          4 bytes
unsigned long                 4 bytes
-----------------------------------------------
long int                      4 bytes
unsigned long int             4 bytes
-----------------------------------------------
long long                     8 bytes
unsigned long long            8 bytes
-----------------------------------------------
long long int                 8 bytes
unsigned long long int        8 bytes
-----------------------------------------------
int8_t                        1 bytes
uint8_t                       1 bytes
-----------------------------------------------
int16_t                       2 bytes
uint16_t                      2 bytes
-----------------------------------------------
int32_t                       4 bytes
uint32_t                      4 bytes
-----------------------------------------------
int64_t                       8 bytes
uint64_t                      8 bytes




CHAR_MIN       0                        
CHAR_MAX        255                       
-----------------------------------------------
UCHAR_MIN      0                        
UCHAR_MAX       255                       
-----------------------------------------------
SHRT_MIN       -32768                   
SHRT_MAX        32767                     
-----------------------------------------------
USHRT_MIN      0                        
USHRT_MAX       65535                     
-----------------------------------------------
INT_MIN        -2147483648              
INT_MAX         2147483647                
-----------------------------------------------
UINT_MIN       0                        
UINT_MAX        4294967295                
-----------------------------------------------
LONG_MIN       -2147483648              
LONG_MAX        2147483647                
-----------------------------------------------
ULONG_MIN      0                        
ULONG_MAX       4294967295                
-----------------------------------------------
LLONG_MIN      -9223372036854775808     
LLONG_MAX       9223372036854775807       
-----------------------------------------------
ULLONG_MIN     0                        
ULLONG_MAX      18446744073709551615  
char                          1 bytes
unsigned char                 1 bytes
-----------------------------------------------
short                         2 bytes
unsigned short                2 bytes
-----------------------------------------------
int                           4 bytes
unsigned int                  4 bytes
-----------------------------------------------
long                          8 bytes
unsigned long                 8 bytes
-----------------------------------------------
long int                      8 bytes
unsigned long int             8 bytes
-----------------------------------------------
long long                     8 bytes
unsigned long long            8 bytes
-----------------------------------------------
long long int                 8 bytes
unsigned long long int        8 bytes
-----------------------------------------------
int8_t                        1 bytes
uint8_t                       1 bytes
-----------------------------------------------
int16_t                       2 bytes
uint16_t                      2 bytes
-----------------------------------------------
int32_t                       4 bytes
uint32_t                      4 bytes
-----------------------------------------------
int64_t                       8 bytes
uint64_t                      8 bytes




CHAR_MIN       -128                     
CHAR_MAX        127                       
-----------------------------------------------
UCHAR_MIN      0                        
UCHAR_MAX       255                       
-----------------------------------------------
SHRT_MIN       -32768                   
SHRT_MAX        32767                     
-----------------------------------------------
USHRT_MIN      0                        
USHRT_MAX       65535                     
-----------------------------------------------
INT_MIN        -2147483648              
INT_MAX         2147483647                
-----------------------------------------------
UINT_MIN       0                        
UINT_MAX        4294967295                
-----------------------------------------------
LONG_MIN       -9223372036854775808     
LONG_MAX        9223372036854775807       
-----------------------------------------------
ULONG_MIN      0                        
ULONG_MAX       18446744073709551615      
-----------------------------------------------
LLONG_MIN      -9223372036854775808     
LLONG_MAX       9223372036854775807       
-----------------------------------------------
ULLONG_MIN     0                        
ULLONG_MAX      18446744073709551615 

테스트 코드

#include <iostream>
#include <iomanip>
#include <climits>

int main() {
    std::cout << std::left << std::setw(30) << "char" << sizeof(char) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned char" << sizeof(unsigned char) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "short" << sizeof(short) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned short" << sizeof(unsigned short) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "int" << sizeof(int) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned int" << sizeof(unsigned int) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "long" << sizeof(long) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned long" << sizeof(unsigned long) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "long int" << sizeof(long int) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned long int" << sizeof(unsigned long int) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "long long" << sizeof(long long) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned long long" << sizeof(unsigned long long) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "long long int" << sizeof(long long int) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "unsigned long long int" << sizeof(unsigned long long int) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "int8_t" << sizeof(int8_t) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "uint8_t" << sizeof(uint8_t) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "int16_t" << sizeof(int16_t) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "uint16_t" << sizeof(uint16_t) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "int32_t" << sizeof(int32_t) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "uint32_t" << sizeof(uint32_t) <<  " bytes" << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(30) << "int64_t" << sizeof(int64_t) <<  " bytes" << std::endl;
    std::cout << std::left << std::setw(30) << "uint64_t" << sizeof(uint64_t) <<  " bytes" << std::endl;

    std::cout << std::endl << std::endl << std::endl << std::endl;

    std::cout << std::left << std::setw(15) << "CHAR_MIN" << std::left << std::setw(25) << CHAR_MIN << std::endl << std::left << std::setw(16) << "CHAR_MAX" << std::left << std::setw(26) << CHAR_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "UCHAR_MIN" << std::left << std::setw(25) << 0 << std::endl << std::left << std::setw(16) << "UCHAR_MAX" << std::left << std::setw(26) << UCHAR_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "SHRT_MIN" << std::left << std::setw(25) << SHRT_MIN << std::endl << std::left << std::setw(16) << "SHRT_MAX" << std::left << std::setw(26) << SHRT_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "USHRT_MIN" << std::left << std::setw(25) << 0 << std::endl << std::left << std::setw(16) << "USHRT_MAX" << std::left << std::setw(26) << USHRT_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "INT_MIN" << std::left << std::setw(25) << INT_MIN << std::endl << std::left << std::setw(16) << "INT_MAX" << std::left << std::setw(26) << INT_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "UINT_MIN" << std::left << std::setw(25) << 0 << std::endl << std::left << std::setw(16) << "UINT_MAX" << std::left << std::setw(26) << UINT_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "LONG_MIN" << std::left << std::setw(25) << LONG_MIN << std::endl << std::left << std::setw(16) << "LONG_MAX" << std::left << std::setw(26) << LONG_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "ULONG_MIN" << std::left << std::setw(25) << 0 << std::endl << std::left << std::setw(16) << "ULONG_MAX" << std::left << std::setw(26) << ULONG_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "LLONG_MIN" << std::left << std::setw(25) << LLONG_MIN << std::endl << std::left << std::setw(16) << "LLONG_MAX" << std::left << std::setw(26) << LLONG_MAX << std::endl;
    std::cout << "-----------------------------------------------" << std::endl;
    std::cout << std::left << std::setw(15) << "ULLONG_MIN" << std::left << std::setw(25) << 0 << std::endl << std::left << std::setw(16) << "ULLONG_MAX" << std::left << std::setw(26) << ULLONG_MAX << std::endl;

    return 0;
}
반응형
:

std::lock_guard, std::unique_lock 에서 lock, unlock 호출 시점 확인 하기

프로그래밍/c,c++ 2021. 12. 1. 17:50
반응형

std::lock_guard 은 생성 시점에 lock을 호출하고 소멸 시점(블럭 끝)에 unlock을 호출 한다.

 

std::unique_lock 은 생성 시점에 lock을 호출하고 소멸 시점(블럭 끝)에 unlock을 호출 하고

추가로 lock, unlock을 호출 할수 있다(lock 에 대한 상태값 유지).

 

#include <iostream>
#include <string>
#include <mutex>

class TestMutex {
    public:
        void lock() {
            std::cout << "call lock" << std::endl;
        }
        void unlock() {
            std::cout << "call unlock" << std::endl;
        }
};

TestMutex mutex1;

int main() {
    std::cout << "###### lock_guard start" << std::endl;
    {
        std::lock_guard<TestMutex> lockGuard(mutex1);
        std::cout << "lock_guard created" << std::endl;
    }
    std::cout << "###### lock_guard end" << std::endl << std::endl;

    std::cout << "###### unique_lock start" << std::endl;
    {
        std::unique_lock<TestMutex> uniqueLock(mutex1);
        std::cout << "unique_lock created" << std::endl;
    }
    std::cout << "###### unique_lock end" << std::endl << std::endl;

    std::cout << "###### unique_lock start 2" << std::endl;
    {
        std::unique_lock<TestMutex> uniqueLock(mutex1);
        std::cout << "unique_lock created" << std::endl;
        std::cout << "manual call unlock ++" << std::endl;
        uniqueLock.unlock();
        std::cout << "manual call unlock --" << std::endl;
    }
    std::cout << "###### unique_lock end 2" << std::endl << std::endl;

    std::cout << "###### unique_lock start 3" << std::endl;
    {
        std::unique_lock<TestMutex> uniqueLock(mutex1);
        std::cout << "unique_lock created" << std::endl;
        std::cout << "manual call unlock ++" << std::endl;
        uniqueLock.unlock();
        std::cout << "manual call unlock --" << std::endl;
        std::cout << "manual call lock ++" << std::endl;
        uniqueLock.lock();
        std::cout << "manual call lock --" << std::endl;
    }
    std::cout << "###### unique_lock end 3" << std::endl << std::endl;


    return 0;
}

실행 결과

$ ./a.out
###### lock_guard start
call lock
lock_guard created
call unlock
###### lock_guard end

###### unique_lock start
call lock
unique_lock created
call unlock
###### unique_lock end

###### unique_lock start 2
call lock
unique_lock created
manual call unlock ++
call unlock
manual call unlock --
###### unique_lock end 2

###### unique_lock start 3
call lock
unique_lock created
manual call unlock ++
call unlock
manual call unlock --
manual call lock ++
call lock
manual call lock --
call unlock
###### unique_lock end 3
반응형
:

데드락이 발생하는 케이스

프로그래밍/c,c++ 2021. 11. 30. 17:35
반응형

단일 스레드 데드락

#include <mutex>    
                                                                                                                                                                                                                                         
std::mutex mutex1;    
    
/////////// Lock 이 걸린 상태에서 다시 lock 호출    
void deadlock_1() {    
    std::lock_guard<std::mutex> lockGuard(mutex1);    
    deadlock_1_1();    
}                                                                                                                                                                                                                                    
     
void deadlock_1_1() {    
    std::lock_guard<std::mutex> lockGuard(mutex1); // 걸려 있는 lock에 대해 다시 lock 시도   
}    
     
////////// Lock 이 걸린 상태에서 돌고 돌아 다시 lock 호출, 많이 돌고 돌다 lock 이 걸리면 ...    
void deadlock_2() {    
    std::lock_guard<std::mutex> lockGuard(mutex1);    
    deadlock_2_1();    
}    
                                                                                     
void deadlock_2_1() {                                                                
    deadlock_2();                               // 재귀 호출로 다시 lock 시도                                                                  
}

멀티 스레드 데드락 - 번호 순서로 실행 되면 데드락 발생

#include <mutex>    
                                                                                                                                                                                                                                         
std::mutex mutex1;    
std::mutex mutex2; 

void deadlock_3_thread_1() {
    std::lock_guard<std::mutex> lockGuard(mutex1);    // 1   
    std::lock_guard<std::mutex> lockGuard(mutex2);    // 3
}                         
                          
void deadlock_3_thread_2() {
    std::lock_guard<std::mutex> lockGuard(mutex2);    // 2
    std::lock_guard<std::mutex> lockGuard(mutex1);    // 3
}
반응형
:

ubuntu c++ 맨페이지 설치

프로그래밍/c,c++ 2021. 11. 30. 17:07
반응형

터미널에서 간단히 c++ std api 내용 확인 할때

맨페이지 없는 상태

$ man std::lock_guard                        
No manual entry for std::lock_guard

맨페이지 설치

$ sudo apt install libstdc++-10-doc

설치된 맨페이지 확인

$ man std::lock_guard | cat
std::lock_guard< _Mutex >(3cxx)                                                                                                                                                                                                       std::lock_guard< _Mutex >(3cxx)

NAME
       std::lock_guard< _Mutex > - A simple scoped lock type.
......
반응형
:

shell script 에서 ++

프로그래밍/shell script 2021. 11. 26. 18:06
반응형
#! sh

num=0

echo $num
num=$(($num + 1))
echo $num
num=$((num + 1))
echo $num
let num++
echo $num

실행 결과

❯ ./test.sh          
0
1
2
3
반응형
:

Lognote 0.1.6 - Android logcat viewer

프로그래밍/lognote 2021. 11. 24. 16:26
반응형

https://github.com/cdcsgit/lognote/releases/tag/0.1.6

 

Release 0.1.6 · cdcsgit/lognote

Full Changelog: 0.1.5...0.1.6

github.com

 

최신 버전 : https://cdcsman.tistory.com/entry/Lognote-Android-logcat-viewer

 

Lognote - Android logcat viewer for Windows, Linux, Mac

https://github.com/cdcsgit/lognote/releases Releases · cdcsgit/lognote Android logcat viewer. Contribute to cdcsgit/lognote development by creating an account on GitHub. github.com 실행 - windows..

cdcsman.tistory.com

 

version 0.1.6

- 여러파일 동시 열기

- tooltip 추가

- windows drag & drop 개선

- 스크롤백 제한으로 인한 로그 삭제 일시 중지 기능 추가

 

version 0.1.5

- 로그 컬러 세팅 추가

- 필터 로그뷰에서 커서 이동시 전체 로그뷰 커서 이동 개선

- 스크롤백 라인 제한으로 인한 로그 삭제시 뷰 동작 개선

 

version 0.1.4
- 설정에서 폰트 변경시 즉시 적용
- 필터 저장 및 가져오기

version 0.1.1
- 팝업메뉴 추가
- 대소문자 구분

version 0.0.1
- 정규 표현식 필터
- On/Off line 로그 뷰

aa

 

반응형
:

Lognote 0.1.4 - Android logcat viewer

프로그래밍/lognote 2021. 10. 8. 14:09
반응형

https://github.com/cdcsgit/lognote/releases/tag/0.1.4

 

Release 0.1.4 · cdcsgit/lognote

Full Changelog: 0.1.3...0.1.4

github.com

최신 버전 : https://cdcsman.tistory.com/entry/Lognote-Android-logcat-viewer

 

Lognote - Log viewer, Android logcat viewer for Windows, Linux, Mac

https://github.com/cdcsgit/lognote/releases Releases · cdcsgit/lognote Log viewer, Android logcat viewer for Windows, Linux, Mac - cdcsgit/lognote github.com 텍스트 로그 파일 보기(필터) Logcat 보기(Online/Offline) 정규 표현식 필터 에

cdcsman.tistory.com

version 0.1.4
- 설정에서 폰트 변경시 즉시 적용
- 필터 저장 및 가져오기

version 0.1.1
- 팝업메뉴 추가
- 대소문자 구분

version 0.0.1
- 정규 표현식 필터
- On/Off line 로그 뷰

 

반응형
:

Lognote 0.1.1 - Android logcat viewer

프로그래밍/lognote 2021. 9. 1. 15:28
반응형

github.com/cdcsgit/lognote/releases

 

Releases · cdcsgit/lognote

Contribute to cdcsgit/lognote development by creating an account on GitHub.

github.com

 

최신 버전 : https://cdcsman.tistory.com/entry/Lognote-Android-logcat-viewer

 

Lognote - Log viewer, Android logcat viewer for Windows, Linux, Mac

https://github.com/cdcsgit/lognote/releases Releases · cdcsgit/lognote Log viewer, Android logcat viewer for Windows, Linux, Mac - cdcsgit/lognote github.com 텍스트 로그 파일 보기(필터) Logcat 보기(Online/Offline) 정규 표현식 필터 에

cdcsman.tistory.com

 

version 0.1.1

- 팝업메뉴 추가

- 대소문자 구분

 

version 0.0.1

- 정규 표현식 필터

- On/Off line 로그 뷰

 

반응형
:

개발자...

프로그래밍 2021. 3. 12. 18:31
반응형

제발 코딩 룰 좀.

반복되는건 따로.

언어도 바뀐다. 20년 전 c++ 지금 c++ 은 다르다.

리팩토링... 바꾸고 싶은 코드는 많은데 바꾸면 내책임 ㅡㅡ

반응형
:

int 를 hex string 으로 변환

프로그래밍/kotlin 2021. 2. 16. 13:48
반응형

hexStr = java.lang.Integer.toHexString(num)

반응형
: