블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
  • total
  • today
  • yesterday

Category

Steve Oualline


Scope and Class

The scope of a variable is the area of the program in which the variable is valid.

A block is a section of code enclosed in curly braces.

The declaration of a local variable takes precedence over the global declaration inside the small block in which the local variable is declared.   (127쪽)

The class of a variable may be either permanent or temporary.
Global variables are always permanent. They are created and initialized before the program starts and remain until it terminates.    (129쪽)

Temporary variables are allocated from a section of memory called the stack at the beginning of the block. The space used by the temporary variables is returned to the stack at the end of the block. Each time the block is entered, the temporary variables are initialized.   (129쪽)

Temporary variables are sometimes refered to as automatic variables because the space for them is allocated automatically.   (130쪽)


stack
webopedia:
In programming, a special type of data structure in which items are removed in the reverse order from that in which they are added, so the most recently added item is the first one removed. This is also called last-in, first-out (LIFO).
Adding an item to a stack is called pushing. Removing an item from a stack is called popping.

cf.
http://cplusplus.com/reference/stl/stack/
Cprogramming.com: The stack data structure

의문: memory는 CPU 밖에, register는 CPU 안에,  stack은 어디에? memory에?
그럼 stack은 memory인가?
memory에서 stack인 부분과 stack이 아닌 부분을 컴퓨터가 어떻게 구분짓나?
global variables는 프로그램이 끝날 때까지 memory에서 각각 하나의 주소값을 유지하나?

http://en.wikipedia.org/wiki/Stack_%28data_structure%29
a stack is an abstract data type and data structure based on the principle of Last In First Out (LIFO).

A typical stack is an area of computer memory with a fixed origin and a variable size. Initially the size of the stack is zero. A stack pointer, usually in the form of a hardware register, points to the most recently referenced location on the stack; when the stack has a size of zero, the stack pointer points to the origin of the stack.

The two operations applicable to all stacks are:

  • a push operation, in which a data item is placed at the location pointed to by the stack pointer, and the address in the stack pointer is adjusted by the size of the data item;
  • a pop or pull operation: a data item at the current location pointed to by the stack pointer is removed, and the stack pointer is adjusted by the size of the data item.


There are many variations on the basic principle of stack operations. Every stack has a fixed location in memory at which it begins. As data items are added to the stack, the stack pointer is displaced to indicate the current extent of the stack, which expands away from the origin (either up or down, depending on the specific implementation).

A stack is usually represented in computers by a block of memory cells, with the "bottom" at a fixed location, and the stack pointer holding the address of the current "top" cell in the stack. The top and bottom terminology are used irrespective of whether the stack actually grows towards lower memory addresses or towards higher memory addresses.


Many CPUs have registers that can be used as stack pointers.

In application programs written in a high level language, a stack can be implemented efficiently using either arrays or linked lists.


The size of the stack depends on the system and compiler you are using. On many UNIX systems, the program is automatically allocated the largest possible stack.   (129쪽)

cp. register
http://en.wikipedia.org/wiki/Processor_register

의문:
register에도 주소가 있을까?
register는 memory의 주소와 그 주소에 들어가는 데이터를 가지고 있는 것인가? (그렇다면 '&변수명'과 관계가 있는가?)
register가 stack에도 마찬가지로 작용하나?
만약에 그렇다면, stack에서 memory의 주소에 들어가는 데이터가 자꾸 변할 때마다 register 역시 그 정보를 동시에 알고 있다는 뜻인가? 그렇다면, 어떻게 아는 것인가? 그러니까 stack과 register는 같이 움직이나?


cf. static
It indicates that a variable is local to the current file.    (129쪽)


Functions

Functions allow us to group commonly used  code into a compact until that can be used repeatedly.   (130쪽)

Function: Name, Description, Parameters, Returns, (file formats, references, or notes)

C uses a form of parameter passing called "Call by value".   (131쪽)



function prototype

ref.   http://www.cprogramming.com/tutorial/lesson4.html
Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be.


void


Structured Programming

Structured programming techniques are ways of dividing up or structuring a program into small, well-defined functions.   (135쪽)

top-down programming
bottom-up programming


Recursion

Recurion occurs when a fuction calls itself directly or indirectly.    (136쪽)

1. It must have an ending point.
2. It must make the problem simpler.




posted by maetel