Programming/C Win32 MFC2009. 4. 22. 11:25
sizeof()는 type의 크기나 문자열의 길이를 알아 낼때 쓰이는 유용한 녀석이다
근데 문제는 생긴 꼴은 function() 이라서 대충 보면 함수 같은데
엄밀하게 이녀석은 operator이다.(연산자)

그런 이유로, sizeof()는 runtime시에 값이 치환되는것이 아닌 compile time에 값이 치환된다.


#include "stdio.h"
#include "stdlib.h"
#include "string.h"

void main()
{
	char str[] = "Hello World";
	char *str2 = NULL;

	printf("sizeof(char)  %d\n",sizeof(char));
	printf("sizeof(short) %d\n",sizeof(short));
	printf("sizeof(int)   %d\n",sizeof(int));
	printf("sizeof(str)   %d\n",sizeof(str));
	printf("sizeof(*str)  %d\n",sizeof(*str));
	
	str2 = (char*)malloc(12);
	printf("sizeof(str2)  %d\n",sizeof(str2));
	printf("sizeof(*str2) %d\n",sizeof(*str2));

	free(str2);
}

sizeof(char)  1
sizeof(short) 2
sizeof(int)   4
sizeof(str)   12
sizeof(*str)  1
sizeof(str2)  4
sizeof(*str2) 1

처럼 runtime시에 할당되는 크기는 알 수가 없다.
위의 것은 12바이트 문자열이므로(11 + 1byte NULL) 12가 나왔지만
아래는 *char 즉, 포인터 형으로 4byte가 나온것이다.

[링크 : http://www.velocityreviews.com/forums/t635338-sizeof-calculated-at-compile-time-or-run-time.html
Posted by 구차니
Programming/css2009. 4. 9. 10:06
Mr.Dust 님의 CSS Naked Day를 보고 따라해보려고 쑈를 했다 ^^;


일단 아무생각없이 HTML/CSS 에서 CSS를 전부 지우면 아래와 같은 에러가 나서 저장이 안된다.

그러면 아래의 내용을 넣으면 된다.


@charset "utf-8";
* {
}

'Programming > css' 카테고리의 다른 글

CSS / JS 파일 용량 줄이기  (0) 2015.09.18
css selector  (0) 2015.09.14
css 관련  (4) 2015.09.08
css box model  (0) 2014.05.15
크롬과 IE에서 CSS 차이점 - body / background-color  (2) 2011.03.09
Posted by 구차니
Programming/C Win32 MFC2009. 3. 24. 11:16
main 함수의 기본 프로토타입은 int main(int argc, char *argv[]) 이다.
물론 귀찮아서 void main()으로 주로 쓰긴 하지만, 인자를 받기 위해서는 저 프로토타입을 써야 한다.
아무튼 막상 인자로 받다가 그 인자를 만들어 내려니 자꾸만 안되서 머리를 데굴데굴 굴려봤다.




음.. argv가 argument array인데,
argv[0]은 실행프로그램(자기자신)의 경로+이름
argv[1] 부터 인자가 들어 간다.
그리고 마지막은 null이 들어간다.

    int argc = 2;
    char str1[] = "a.out";
    char str2[] = "/dev/fb0";
    char str3[] = "";
    char *strs[] = {str1,str2,str3};
    char **argv = strs;
아무튼 꼼지락 대면서 겨우겨우 맞춰서 넣은 argc, argv 값들.. 하아..
조금 더 추려내면

    int argc = 2;
    char *strs[] = {"a.out", "/dev/fb0", ""};
    char **argv = strs;


간단하게 하는 방법은 정녕없는 것인가!
Posted by 구차니
Programming/C Win32 MFC2009. 3. 16. 12:33
있을 줄 알았는데 없다는 사실에 웬지 "초~ 쇼크~"(하레와 구우 버전)


Besides, unix way is to be ascetic and elegant, avoiding putting messy and slow algorithms under the hood, and filecopy is definitely slow ( you want syscall with fast filecopy - great, here's hardlink for you ).

[링크 : http://www.perlmonks.org/?node_id=389823]


생각해보니.. UNIX의 설계 철학중 simple is beautiful이 근간이 되어 있다는게 생각이 났다.
cp() 가 빈번하게 사용될지라도, 느린 함수이고(최소한 fopen/fread/fwrite/fclose 4개의 함수를 사용한다)
이러한 복잡한 함수는 단순함의 철학에 위배가 되기에 많이 사용함에도 불구하고
cp() 라는 함수가 존재하지 않는것 같다.



그래도...
rename() remove() 이런건 있으면서 cp()가 없다는 건 웬지 억울한 느낌?


Posted by 구차니
Programming/C Win32 MFC2009. 2. 24. 11:01
상당히 즐겨보고 애용하는 문서 입니다.
ANSI C에 관련된 함수 정리 및 어떤 파일에 어떤 함수가 있는지를 쉽게 알 수 있고
함수의 프로토타입과 설명이 있어서 C언어 프로그래머들에게 매우 유용한 자료입니다.

2.   Library
     2.1  assert.h
          2.1.1     assert
     2.2  ctype.h
          2.2.1     is... Functions
          2.2.2     to... Functions
     2.3  errno.h 
          2.3.1     EDOM
          2.3.2     ERANGE
          2.3.3     errno   
     2.4  float.h
          2.4.1     Defined Values
     2.5  limits.h
          2.5.1     Defined Values
     2.6  locale.h
          2.6.1     Variables and Definitions
          2.6.2     setlocale
          2.6.3     localeconv
     2.7  math.h
          2.7.1     Error Conditions
          2.7.2     Trigonometric Functions
               2.7.2.1   acos
               2.7.2.2   asin
               2.7.2.3   atan
               2.7.2.4   atan2
               2.7.2.5   cos
               2.7.2.6   cosh
               2.7.2.7   sin
               2.7.2.8   sinh
               2.7.2.9   tan
               2.7.2.10  tanh
          2.7.3     Exponential, Logarithmic, and Power Functions
               2.7.3.1   exp
               2.7.3.2   frexp
               2.7.3.3   ldexp
               2.7.3.4   log
               2.7.3.5   log10
               2.7.3.6   modf
               2.7.3.7   pow
               2.7.3.8   sqrt
          2.7.4     Other Math Functions
               2.7.4.1   ceil
               2.7.4.2   fabs
               2.7.4.3   floor
               2.7.4.4   fmod
     2.8  setjmp.h
          2.8.1     Variables and Definitions
          2.8.2     setjmp
          2.8.3     longjmp
     2.9  signal.h
          2.9.1     Variables and Definitions
          2.9.2     signal
          2.9.3     raise
     2.10 stdarg.h
          2.10.1    Variables and Definitions
          2.10.2    va_start
          2.10.3    va_arg
          2.10.4    va_end
     2.11 stddef.h
          2.11.1    Variables and Definitions
     2.12 stdio.h
          2.12.1    Variables and Definitions
          2.12.2    Streams and Files
          2.12.3    File Functions
               2.12.3.1  clearerr
               2.12.3.2  fclose
               2.12.3.3  feof
               2.12.3.4  ferror
               2.12.3.5  fflush
               2.12.3.6  fgetpos
               2.12.3.7  fopen
               2.12.3.8  fread
               2.12.3.9  freopen
               2.12.3.10 fseek
               2.12.3.11 fsetpos
               2.12.3.12 ftell
               2.12.3.13 fwrite
               2.12.3.14 remove
               2.12.3.15 rename
               2.12.3.16 rewind
               2.12.3.17 setbuf
               2.12.3.18 setvbuf
               2.12.3.19 tmpfile
               2.12.3.20 tmpnam
          2.12.4    Formatted I/O Functions
               2.12.4.1  ...printf Functions
               2.12.4.2  ...scanf Functions
          2.12.5    Character I/O Functions
               2.12.5.1  fgetc
               2.12.5.2  fgets
               2.12.5.3  fputc
               2.12.5.4  fputs
               2.12.5.5  getc
               2.12.5.6  getchar
               2.12.5.7  gets
               2.12.5.8  putc
               2.12.5.9  putchar
               2.12.5.10 puts
               2.12.5.11 ungetc
          2.12.7    Error Functions
               2.12.7.1  perror
     2.13 stdlib.h
          2.13.1    Variables and Definitions
          2.13.2    String Functions
               2.13.2.1  atof
               2.13.2.2  atoi
               2.13.2.3  atol
               2.13.2.4  strtod
               2.13.2.5  strtol
               2.13.2.6  strtoul
          2.13.3    Memory Functions
               2.13.3.1  calloc
               2.13.3.2  free
               2.13.3.3  malloc
               2.13.3.4  realloc
          2.13.4    Environment Functions
               2.13.4.1  abort
               2.13.4.2  atexit
               2.13.4.3  exit
               2.13.4.4  getenv
               2.13.4.5  system
          2.13.5    Searching and Sorting Functions
               2.13.5.1  bsearch
               2.13.5.2  qsort
          2.13.6    Math Functions  
               2.13.6.1  abs
               2.13.6.2  div
               2.13.6.3  labs
               2.13.6.4  ldiv
               2.13.6.5  rand
               2.13.6.6  srand
          2.13.7    Multibyte Functions
               2.13.7.1  mblen
               2.13.7.2  mbstowcs
               2.13.7.3  mbtowc
               2.13.7.4  wcstombs
               2.13.7.5  wctomb
     2.14 string.h
          2.14.1    Variables and Definitions
          2.14.2    memchr
          2.14.3    memcmp
          2.14.4    memcpy
          2.14.5    memmove
          2.14.6    memset
          2.14.7    strcat
          2.14.8    strncat
          2.14.9    strchr
          2.14.10   strcmp
          2.14.11   strncmp
          2.14.12   strcoll
          2.14.13   strcpy
          2.14.14   strncpy
          2.14.15   strcspn
          2.14.16   strerror
          2.14.17   strlen
          2.14.18   strpbrk
          2.14.19   strrchr
          2.14.20   strspn
          2.14.21   strstr
          2.14.22   strtok
          2.14.23   strxfrm
     2.15 time.h 
          2.15.1    Variables and Definitions
          2.15.2    asctime
          2.15.3    clock
          2.15.4    ctime
          2.15.5    difftime
          2.15.6    gmtime
          2.15.7    localtime
          2.15.8    mktime
          2.15.9    strftime
          2.15.10   time
머.. 위에 링크 내용만 보면 필요 하신분들은 알아서 아래 다운을 클릭 하시기를 -ㅁ-

참고 사항으로
c_guide.tar.gz 26-Feb-2002 14:50 202K <- 업데이트 안된지 오래된 문서입니다만, reference인 관계로 오래된 만큼 치명적인
문제점은 없다고 보여 집니다.

[다운 : http://www.acm.uiuc.edu/webmonkeys/book/c_guide.tar.gz]
[링크 : http://www.acm.uiuc.edu/webmonkeys/book/c_guide/index.html]
Posted by 구차니
syntax highlight 관련해서 찾다가 신경을 쓰지 않던 Regular expression을 보게 되었다.

dp.sh.RegexLib = {
	MultiLineCComments : new RegExp('/\\*[\\s\\S]*?\\*/', 'gm'),
	SingleLineCComments : new RegExp('//.*$', 'gm'),
	SingleLinePerlComments : new RegExp('#.*$', 'gm'),
	DecimalValue : new RegExp('[0-9]+','g'),
	HexaValue : new RegExp('[0][xX][A-Fa-f0-9]+','g'),
	DoubleQuotedString : new RegExp('"(?:\\.|(\\\\\\")|[^\\""\\n])*"','g'),
	SingleQuotedString : new RegExp("'(?:\\.|(\\\\\\')|[^\\''\\n])*'", 'g')
};


이런 부분이 shCore.js에 들어 있는데 RegExp의 인자중 'g' 'gm' 부분이 먼지 몰라서 찾아 보게 되었다.

Global match
Ignore case
match over Multiple line
stickY - new in FireFox 3

[참고 : http://user.chollian.net/~spacekan/source/string/regExp.htm]
[참고  : https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/RegExp]

man grep - Regular expression

'Programming > regexp(정규표현식)' 카테고리의 다른 글

정규 표현식.. 반복  (0) 2019.09.17
정규표현식 n개 이상  (0) 2019.08.30
regexp non-capturing group  (0) 2019.08.22
정규표현식 - 특정 내용 삭제하기  (0) 2019.04.02
Posted by 구차니
Programming/C Win32 MFC2009. 1. 2. 11:20
array(행렬/배열)는 동일 타입의 변수를 나열한 것이다.
시작부분의 인덱스는 0이고 마지막 인덱스는 n - 1 이다.

즉, 행렬의 인덱스는 마이너스 값이 될 수 없다는 의미이다.

그런 이유로 array[idx] 에서 idx의 타입이 unsigned 형이 아니라면
이러한 경고를 출력해 주는 것이다.

[링크 : http://www.devolution.com/pipermail/sdl/2003-August/056006.html]
Posted by 구차니
Programming/C Win32 MFC2008. 12. 30. 00:48
open이 있으면 close가 있는 법. 레지스트리 역시 open / create를 했으면 close를 해주어야 한다.
hKey [in]

A handle to the open key to be closed. The handle must have been opened by the RegCreateKeyEx, RegCreateKeyTransacted, RegOpenKeyEx, RegOpenKeyTransacted, or RegConnectRegistry function.


Remarks

The handle for a specified key should not be used after it has been closed, because it will no longer be valid. Key handles should not be left open any longer than necessary.

The RegCloseKey function does not necessarily write information to the registry before returning; it can take as much as several seconds for the cache to be flushed to the hard disk. If an application must explicitly write registry information to the hard disk, it can use the RegFlushKey function. RegFlushKey, however, uses many system resources and should be called only when necessary.


[RegOpenKey : http://msdn.microsoft.com/en-us/library/ms724895(VS.85).aspx]
[RegCloseKey : http://msdn.microsoft.com/en-us/library/ms724837(VS.85).aspx]
[RegCreateKey : http://msdn.microsoft.com/en-us/library/ms724842(VS.85).aspx]
[RegDeleteKey : http://msdn.microsoft.com/en-us/library/ms724845(VS.85).aspx]
Posted by 구차니
Programming/C Win32 MFC2008. 12. 26. 10:45
구글링을 하면서 찾아 보니
GetCurrentDirectory라는 Win32 API가 존재 하는데,
이녀석으로 할 경우 FILE dialog에서 경로를 변경시 다른 경로가 나올 우려가 있다고 한다.

그래서 GetModuleFileName 이라는 함수를 사용하라는데,
먼소리여 -ㅁ-!

[참조 : http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=806]

Code:
char path[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
MessageBox(NULL, path, NULL, NULL);

[출처 : http://www.codeguru.com/forum/showthread.php?threadid=462232]


Run-Time Library Reference
_pgmptr, _wpgmptr
The path of the executable file. Deprecated; use _get_pgmptr and _get_wpgmptr.

Variable Required header Compatibility

_pgmptr, _wpgmptr

<stdlib.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Server 2003

좀 더 간단한 녀석이 있어 보인다.

[원본 : http://msdn.microsoft.com/en-us/library/tza1y5f7(VS.80).aspx]



간단한 테스트 결과

1. VC++ 6.0 컴파일 환경 설정

2. 소스코드 작성
#include <windows.h>

void main()
{
    char path[MAX_PATH];
    GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
    printf("path[%s]\n",path);
    GetCurrentDirectory(MAX_PATH,path);
    printf("path[%s]\n",path);
}

3. 결과
path[C:\Documents and Settings\morpheuz\바탕 화면\tt\Debug\t.exe]
path[C:\]
Press any key to continue


Posted by 구차니
Programming/C Win32 MFC2008. 12. 18. 13:41
아래는 frhed 프로그램의 레지스트리 등록 부분의 소스이다.

    case IDM_CONTEXT:
        if (MF_CHECKED == GetMenuState(hMenu, IDM_CONTEXT, 0))
        {
           //WinNT requires the key to have no subkeys
            RegDeleteKey(HKEY_CLASSES_ROOT, "*\\shell\\Open in frhed\\command");
            RegDeleteKey(HKEY_CLASSES_ROOT, "*\\shell\\Open in frhed");
        }
        else
        {
            HKEY key1;
            LONG res = RegCreateKey(HKEY_CLASSES_ROOT,
                "*\\shell\\Open in frhed\\command",
                &key1);
            if (res == ERROR_SUCCESS)
            {
                char cmd[MAX_PATH];
                int len = sprintf(cmd, "%s %%1", _pgmptr);
                RegSetValue(key1, NULL, REG_SZ, cmd, len);
            }
        }
        break;
    case IDM_UNKNOWN:
        if (MF_CHECKED == GetMenuState(hMenu, IDM_UNKNOWN, 0))
        {
            HKEY hk;
            //WinNT requires the key to have no subkeys
            RegDeleteKey(HKEY_CLASSES_ROOT, "Unknown\\shell\\Open in frhed\\command");
            RegDeleteKey(HKEY_CLASSES_ROOT, "Unknown\\shell\\Open in frhed");
            if (ERROR_SUCCESS == RegOpenKey(HKEY_CLASSES_ROOT, "Unknown\\shell", &hk))
            {
                RegDeleteValue(hk, NULL);
                RegCloseKey(hk);
            }
        }
        else
        {
            HKEY key1;
            LONG res = RegCreateKey(HKEY_CLASSES_ROOT,
                "Unknown\\shell\\Open in frhed\\command",
                &key1);
            if (res == ERROR_SUCCESS)
            {
                char cmd[MAX_PATH];
                int len = sprintf(cmd, "%s %%1", _pgmptr);
                RegSetValue(key1, NULL, REG_SZ, cmd, len);
            }
        }
        break;
    case IDM_DEFAULT:
        if (MF_CHECKED == GetMenuState(hMenu, IDM_DEFAULT, 0))
        {
            HKEY hk;
            if (ERROR_SUCCESS == RegOpenKey(HKEY_CLASSES_ROOT, "Unknown\\shell", &hk))
            {
                RegDeleteValue(hk, NULL);
                RegCloseKey(hk);
            }
        }
        else
        {
            RegSetValue(HKEY_CLASSES_ROOT, "Unknown\\shell", REG_SZ, "Open in frhed", 13);
        }
        break;


notepad2의 아쉬운점이 컨텍스트 메뉴를 지원하지 않는 다는 점이었는데, 이 부분을 응용하여 적용하면
notepad2의 효용이 200배는 증가 할 듯 하다.
Posted by 구차니