요즘들어 XML 공부 한답시고 시작했는데 Javascript로 빠져들고 있다.
예전에는 c만을 경배하다 보니 javascript는 무시했는데 생각보다 강력하고, 생각보다 c 와 유사하며, 생각보다 재미있다.

요즘하는 짓꺼리(?)는
javascript로 웹 브라우저 처럼 프레임 문서 만들어서 조작하기.
이게되면은 다음번에는 xml을 이용해서 단어장이나 해봐야지 -ㅁ-

[링크 : http://www.cadvance.org/doc/java]

'Programming > javascript & HTML' 카테고리의 다른 글

javascript - for / for .. in  (0) 2010.07.18
javascript - 변수 타입  (0) 2010.07.18
javascript template  (0) 2010.07.18
core javascript 문서  (2) 2010.07.18
JSON - JavaScript Object Notation  (2) 2010.06.07
Posted by 구차니
Programming/C Win32 MFC2010. 7. 4. 23:50
WM_DEVICECHANGE 를 통해서 장치의 변경을 알려준다고 한다.
(머.. 내가 쓸일이 있을려나..)

[링크 : http://blog.kkomzi.net/80] << 요거 참조
[링크 : http://www.codeproject.com/kb/dotnet/devicevolumemonitor.aspx]
[링크 : http://bytes.com/topic/c-sharp/answers/264280-how-can-i-detect-cdrom-usb-device-insertions]

[링크 : http://msdn.microsoft.com/en-us/library/aa363480%28VS.85%29.aspx]
Posted by 구차니
Firefox 즐겨찾기를 내보내는데 json 이라는 확장자가 생겼다.
머하는 확장자인가 해서 찾아 봤더니

JavaScript Object Notation

의 약자이고, 일종의 데이터 교환을 위한 텍스트 파일(이러한 컨셉은 XML과 유사)이다.

[링크 : http://www.json.org/json-ko.html]

'Programming > javascript & HTML' 카테고리의 다른 글

javascript - for / for .. in  (0) 2010.07.18
javascript - 변수 타입  (0) 2010.07.18
javascript template  (0) 2010.07.18
core javascript 문서  (2) 2010.07.18
javascript 관련 링크  (2) 2010.07.18
Posted by 구차니
2010/04/22 - [Programming/C / Win32 / MFC] - 변수인데 왜 operation on 'variable' may be undefined 야?

디스어셈블된 내용중에
lea         edi,[ebp-48h]
이러한 부분이 있었는데 []의 의미를 몰랐다가 이제서야 찾아본다.
[]는 C언어의 []와 유사하게 그 변수의 내용을 메모리 번지로 해석해서 그 번지의 내용을 받아오는 연산자이다.
그러니까 ebp의 내용에서 0x48을 뺀 주소를 edi에 저정하라는 의미이다. (LEA)

LEA--Load Effective Address

Opcode

Instruction

Description

8D /r

LEA r16,m

Store effective address for m in register r16

8D /r

LEA r32,m

Store effective address for m in register r32


[링크 : http://www.intel.com/software/.../instruct32_hh/vc150.htm]

8.9.6 메모리 참조
------------------

  인텔문법에서 메모리를 간접적으로 참조하는 형식은 다음과 같다.
    SECTION:[BASE + INDEX*SCALE + DISP]
  이것은 다음과 같은 AT&T 방식으로 참조된다.
    SECTION:DISP(BASE, INDEX, SCALE)

[링크 : http://vozlt.tistory.com/8]

'Programming > Assembly(어셈블리)' 카테고리의 다른 글

.DATA? 지시어  (0) 2011.07.31
x86 register  (2) 2011.07.17
PowerPC(PPC) 어셈관련 내용  (0) 2011.04.04
어셈블리 언어  (0) 2010.05.03
어셈블리 언어 기본 템플릿  (0) 2010.04.17
Posted by 구차니

'Programming > Assembly(어셈블리)' 카테고리의 다른 글

.DATA? 지시어  (0) 2011.07.31
x86 register  (2) 2011.07.17
PowerPC(PPC) 어셈관련 내용  (0) 2011.04.04
어셈블리 메모리 참조 (x86 memory addressing)  (0) 2010.05.03
어셈블리 언어 기본 템플릿  (0) 2010.04.17
Posted by 구차니
Programming/C Win32 MFC2010. 4. 22. 14:28

#include "stdio.h"

int main(int argc, char *argv[])
{
	int x = 1;
	printf("%d %d %d\n", ++x, x, x++);
	return 0;
}

You're running into two issues:

1. Undefined behavior -- you are attempting to modify the value of an
object more than once between sequence points, and the Standard imposes
no requirement on how to handle that behavior. Basically, any
expression of the forms:

i = i++;
j = k++ * k++;
foo(i,i++,--i);

invoke undefined behavior. Read up on the semantics of the "++" and
"--" operators in an *authoritative* reference (the Standard would
obviously be one, but also K&R2 or H&S5); they don't work the way most
people think they should.

2. Order of evaluation -- AFAIK, there's no requirement that
expressions in a function parameter list be evaluated in any particular
order. At first blush, it *looks* like the arguments were evaluated
from right to left (if x = 1, then x++ evaluates to 1, with the side
effect that x == 2, and ++x evaluates to 3, with the side effect that x
== 3), but given that you've invoked undefined behavior the actual
reason may be something else entirely.

[링크 : http://bytes.com/topic/c/answers/222558-operation-x-may-undefined]

위의 소스를 gcc -Wall 옵션을 주고 컴파일 할 경우에
$ gcc -Wall cc_test.c
cc_test.c: In function ‘main’:
cc_test.c:6: warning: operation on ‘x’ may be undefined
cc_test.c:6: warning: operation on ‘x’ may be undefined
이런 경고가 발생한다.

분명 x는 변수인데, 그에 대한 operation이 정의되지 않았다는게 무슨 말인지 모르겠지만,
아무튼 실행을 하면
$ ./a.out
3 3 1
요런 희한한 결과가 나온다.

아무튼, calling convention과도 연관이 있어 보이는데,
c언어 특성상 right-left 로 push 하므로(가장 위에는 왼쪽 값이 오도록)
가장 먼저들어가는, 오른쪽 x++ 은 1이 들어가고
1을 더해준다음, 다음 명령어를 수행하면서(++x) 한번에 2가 증가하게 되고
그럼으로 인해 x, ++x 순으로 3이 들어가는게 아닐까 생각된다.

아니면 말구?

[링크 : http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html]


winXP SP3 32bit / VC++ 6 에서 해본 결과
 2 1 1


linux / gcc 결과
 3 3 1


objdump를 소스와 함께 디스어셈블 하기 위해서는
gcc -g 옵션으로 디버깅 정보를 주어야 한다.
[링크 : http://wikidocs.net/mybook/1473]


솔찍히 어셈을 몰라서 모르겠다 ㅋㅋ
결론 : 한줄에 ++나 -- 연산자를 중복으로 사용하지 말자.
Posted by 구차니
음.. 역시 모든 언어는 skeleton code를 외우면 상대적으로 익히기가 쉬운듯!
(문득 C언어 배울때 #include <stdio.h> void main() {} 하던 기억이.. OTL)

.386
.MODEL Flat, STDCALL
.DATA
; Your initialized data. <comment>
.DATA?
;Your uninitialized data. <comment>
.CONST
.CODE
label:
    end label

[링크 : http://win32assembly.online.fr/tut1.html]

'Programming > Assembly(어셈블리)' 카테고리의 다른 글

.DATA? 지시어  (0) 2011.07.31
x86 register  (2) 2011.07.17
PowerPC(PPC) 어셈관련 내용  (0) 2011.04.04
어셈블리 메모리 참조 (x86 memory addressing)  (0) 2010.05.03
어셈블리 언어  (0) 2010.05.03
Posted by 구차니
Programming/언어론2010. 4. 17. 17:39
convention 은

[링크 : http://engdic.daum.net/dicen/contents.do?query1=E255050]
이런 의미를 가지는데, 굳이 해석하자면, 호출 규약 혹은 관용적인 호출방법 이라고 하면 되려나?

아무튼 문득 Iczelion 의 강좌를 읽다보니 어셈블리 기본 구조에
STDCALL 이라는 용어가 나오고, calling convention 이 나오길래 자세히 읽어 봤더니
'함수를 호출시에 인자를 넘겨주는 데이터를 stack에 넣는 방법'을 의미한다.

.MODEL FLAT, STDCALL
.MODEL is an assembler directive that specifies memory model of your program. Under Win32, there's only on model, FLAT model.
STDCALL tells MASM about parameter passing convention. Parameter passing convention specifies the order of  parameter passing, left-to-right or right-to-left, and also who will balance the stack frame after the function call.
Under Win16, there are two types of calling convention, C and PASCAL
C calling convention passes parameters from right to left, that is , the rightmost parameter is pushed first. The caller is responsible for balancing the stack frame after the call. For example, in order to call a function named foo(int first_param, int second_param, int third_param) in C calling convention the asm codes will look like this:

push  [third_param]               ; Push the third parameter
push  [second_param]            ; Followed by the second
push  [first_param]                ; And the first
call    foo
add    sp, 12                                ; The caller balances the stack frame
PASCAL calling convention is the reverse of C calling convention. It passes parameters from left to right and the callee is responsible for the stack balancing after the call.
Win16 adopts
PASCAL convention because it produces smaller codes. C convention is useful when you don't know how many parameters will be passed to the function as in the case of wsprintf(). In the case of wsprintf(), the function has no way to determine beforehand how many parameters will be pushed on the stack, so it cannot do the stack balancing.
STDCALL is the hybrid of C and PASCAL convention. It passes parameter from right to left but the callee is responsible for stack balancing after the call.Win32 platform use STDCALL exclusively. Except in one case: wsprintf(). You must use C calling convention with wsprintf().


[링크 : http://win32assembly.online.fr/tut1.html]

예를 들어, C언어의 경우에는  STDCALL을 사용하며,
인자(argument)들은 오른쪽 부터 stack에 push() 된다.

즉,
push(arg4);
push(arg3);
push(arg2);
push(arg1);
이런식으로 함수 호출시 인자를 넘겨주게 된다.


음.. 개인적인 생각이지만, C언어의 경우 heap은 아래에서 위로 커나가는데 그 방향을 맞추려고
stack에도 데이터를 이렇게 반대 순서로 넣는게 아닐까 싶다.

물론 argument 순서가 의미는 없기 때문에(받아들이는 쪽에서 알아서 받는다면)
가장 위에 첫 인자가 있을 이유는 없는데, 굳이 이런식으로 방향성을 가진다는건...
메모리 구조에 기인한게 아닐려나?

(아니면 말구 -ㅁ-!)

'Programming > 언어론' 카테고리의 다른 글

dangling if-else  (0) 2014.08.13
double의 정확도 자릿수  (0) 2011.03.25
함수 포인터 (function pointer)  (0) 2010.09.16
type system  (0) 2010.09.15
Posted by 구차니
PyObject_GetAttrString() 함수는 파이썬 내의 변수 객체를 받아오는 녀석이다.

PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
Return value: New reference.

Retrieve an attribute named attr_name from object o. Returns the attribute value on success, or NULL on failure. This is the equivalent of the Python expression o.attr_name.


[링크 : http://docs.python.org/c-api/object.html#PyObject_GetAttrString]

문제는 PyObject *o 인데, o는 전체를 의미하는 __main__을 사용하면 될듯하다.
아무튼 간략하게 사용하자면, 이런식으로 문자열을 출력 가능하다.

    Py_Initialize();
        PyRun_SimpleString("teststr=\"test test\"");

        PyObject* po_main = PyImport_AddModule("__main__");
        PyObject* po_dict = PyObject_GetAttrString(po_main, "teststr");

        printf("teststr [%s]\n",PyString_AsString(po_dict));

        Py_DECREF(po_main);
        Py_DECREF(po_dict);

    Py_Finalize();


[링크 : http://koichitamura.blogspot.com/2008/06/this-is-small-python-capi-tutorial.html]
Posted by 구차니
파이썬에서 문자열은 " 나 ' 로 표시가 된다.
하지만 HTML의 <PRE> 태그 처럼 """ 를 사용하면 엔터표시 없이 보이는대로 출력해주는 특이한(?!) 문법이 존재한다.
처음에는 도대체 이녀석을 왜쓸까? 했는데,
python 자체 util 인 pydocs가 문서화를 하는데 __doc__ 사용한다고 한다.

아래는 파이썬 튜토리얼중 문자열에 대한 부분인데,
단순하게 사용법을 출력하기 위해 \n 없이 문자열을 입력하는 것을 보여준다.

Or, strings can be surrounded in a pair of matching triple-quotes: """ or '''. End of lines do not need to be escaped when using triple-quotes, but they will be included in the string.

print """
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to
"""

produces the following output:
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to

[링크 : http://docs.python.org/tutorial/introduction.html#strings]

파이썬 class 문서로서, """A Simple example class"" 는
MyClass.__doc__ attribute로 문자열로 인식이 되며, pydocs나 doxygen에서
이를 이용하여 함수의 간략한 설명을 넣는데 이용될 수 있다.

class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

[링크 : http://docs.python.org/tutorial/classes.html]


위는 전형적인 python 의 주석 스타일이며, 아래는 doxygen을 위한 주석 스타일이다.
그러고 보니.. 파이썬도 #를 이용한 주석을 인정하는군..(Makefile이나 쉘 스크립트는 #로 시작하는 줄은 주석으로 인식함)

For Python there is a standard way of documenting the code using so called documentation strings. Such strings are stored in __doc__ and can be retrieved at runtime. Doxygen will extract such comments and assume they have to be represented in a preformatted way.

"""@package docstring
Documentation for this module.

More details.
"""

def func():
    """Documentation for a function.

    More details.
    """
    pass



## @package pyexample
#  Documentation for this module.
#
#  More details.

## Documentation for a function.
#
#  More details.
def func():
    pass

[링크 : http://www.stack.nl/~dimitri/doxygen/docblocks.html]

'Programming > python(파이썬)' 카테고리의 다른 글

python 버전 골라서 실행하기  (0) 2011.05.08
python C/api - PyObject_GetAttrString()  (0) 2010.04.06
python c/api 관련문서  (0) 2010.03.25
python c/api - Py_DECREF  (0) 2010.03.25
python c/api 에서 모듈 불러오기  (0) 2010.03.19
Posted by 구차니