//**************************************************************************
//구조체 !!
//**************************************************************************
//정의 : 사용자 정의 데이터 타입 !!
//**************************************************************************
// 기본 타입으로 표현하기 힘든것들을 표현하기 위한 방법 !!
#include <iostream>
using namespace std;

class Person
{//속성
private :
int Number; // 번호
int age; // 나이
char name[20]; //이름
int stress; //스트레스
//행동
public :
int GetAge(){
return age;
}

char *GetName(){
return name;
}

void SetAge(int newage)
{
if(newage <= 0)
{
age = 1;
}
else
{
age = newage;
}
}

void speak(){
stress--;
}
void sleeping(){
stress--;
}
void play(){
stress--;
}
void fighting(){
}
void show(){
cout << Number << age << name << endl;
}

};
//접근 제한자!!
//private : 외부로부터 접근을 막는다.!!
//public : 내부 외부 모두에서 접근 할도록 지정 !!
//protected : 상속 : 외부에서는 접근할수 없고 오직 내부,자식에서만 접근 가능

void main()
{
Person LEE;
LEE.play();
int i =  0;
cin >> i;
LEE.SetAge(i);
cout << LEE.GetAge() << endl;
cout << LEE.GetName() << endl;

}


#include <iostream>

//1.
/* new , delete
#include <malloc.h>

using namespace std;

void main()
{
int *p3 = new int;

int *p1 = (int *)malloc(sizeof(int)*10); 
int *p2 = new int[10];
delete p3;
delete [] p2;
free(p1);
int *p1 = (int *)malloc(sizeof(int)*10); //일반화 프로그래밍 !! ->void *  
free(p1);
}*/


//2.
/*

//참조 변수(REF)   & 참조형 변수
//변수에 대한 또다른이름 --> 별명--> 알리아스
using namespace std;
//call by value
void SWAP(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
//c언어 call by ref
void SWAP(int *x, int* y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
// 레퍼런스를 이용한 call by ref
void SWAP(int & x, int & y)
{
int temp = x;
x = y;
y = temp;
}

void main()
{
int x = 10;
int y = 20;
cout << x << "  " << y << endl;
SWAP(&x,&y);
cout << x << "  " << y << endl;
cout << x << "  " << y << endl;
SWAP(x,y);
cout << x << "  " << y << endl;

cout << x << "  " << y << endl;
SWAP(x,y);
cout << x << "  " << y << endl;

int LEE_TAE_WON = 100;
//참조형 변수는 선언과 동시에 참조가 되어야 한다.
int & p = LEE_TAE_WON;
cout << LEE_TAE_WON << endl;
cout <<  p << endl;

}
*/
/*
//3.함수 오버로딩 ( 다중정의 )
//정의 : 같은 이름의 함수가 매개변수의 갯수와 타입에 따라서 
//   서로 다른 함수로 인식 하는 것

using namespace std;
//함수 원형 선언
void print();
void print(int);
void print(int , int);

void main()
{
print();
}

void print()
{
cout << "printf()" << endl;
}
void print(int x)
{
cout <<"printf(int x)" << endl;
}
void print(int x, int y)
{
cout <<"printf(int x,int y)" << endl;
}
*/

/*
//4,디폴트 파라미터 

using namespace std;

void foo(int Snum = 100, int age =20, char *name = "홍길동") 
{
cout <<"학번은"<<Snum<< "나이는" << age<< "살"<< " 이름은 "<<  name << "입니다."<< endl;
}

void main()
{
foo();
}
*/
/*
//함수 오버로딩은 같은 로직의 함수가 매개변수의 타입에 따라 구현될경우사용
//
int plus(int x = 0, int y = 0)
{
return x+y;
}
double plus(float x = 0, float y = 0)
{
return double(x+y);
}
using namespace std;

void main()
{
cout << plus() << endl;
}
*/
/*
#include <malloc.h>
 //c++ 동적 메모리 사용!!
using namespace std;

void main()
{

int *p = (int *)malloc(sizeof(int)*10);

//재할당
p = (int *)realloc(p , _msize(p)*2);
cout <<  _msize(p) << endl;
free(p);

int *p2 = new int[10];
// int *p3 = &(*p2);
p2 = new int[_msize(p2)/sizeof(int)*2];
// memcpy(p3,p2,_msize(p2));
// p3 * 2;

cout << _msize(p2) << endl;
delete [] p2;
}
*/

using namespace std;

int *dong(int size_t=1, bool check_zero=0,int *q=0)
{
int *temp = new int[size_t];
if(check_zero)
{
memset(temp,0,_msize(temp));
}
if(q)
{
memcpy(temp,q,sizeof(int)*size_t);
delete [] q;
}
return temp;
}
void main()
{
int *p = new int[10];
p[0] = 5;
p[2] = 3;
p = dong(3,1,p);
cout << p[1] << endl;
cout << _msize(p) << endl;
}


#include <iostream>
//using namespace std;
//using namespace A;

int x=200;
namespace B
{
//using std::cout;
//using std::endl;
using namespace std;

inline void foo() //함수를 호출하는 곳에서 바로 실행하게 해줌. 메모리 할당 X,메모리 절약 실행속도 업
// 단점 함수에잇는 내용이 많아지면 
{
/*cout.operator << (10);
cout <<"1" << endl;
cout << 10 << 29 << "aa"<<'X'<<3.14<< endl;

int x;
cin >> x;
cout << x<< endl;
*/
//int x=100;
//cout << ::x << endl;
/*
float f = 3.14;
int x = int(f);

cout << x << endl;
*/
cout<<"XXXXXXXX"<<endl;
cout<<"XXXXXXXX"<<endl;
cout<<"XXXXXXXX"<<endl;
}
}
//태그가 타입으로 승격
//구조체 태그로부터 변수를 바로 선언할수 있다.

struct BOOK
{
int price;
int page;
};

void main()
{
//B::foo();
BOOK *p1 = (BOOK *)malloc(sizeof(BOOK)*10);

free(p1);
}

//함수 오버로딩
//구조체


#include <stdio.h>

#include <stdio.h>

#include <windows.h>

void main()

{

            

             //루틴의속도측정을위해사용

             LARGE_INTEGER liCounter1, liCounter2, liFrequency;

    QueryPerformanceFrequency(&liFrequency);

    QueryPerformanceCounter(&liCounter1);

 

             //10000000000 번의for 루프

             for(int i=1000000000; i > 0; i--)

             {                                      

             }

              QueryPerformanceCounter(&liCounter2);

 

              //측정결과

    printf("c 언어수행시간= %f \n", (double)(liCounter2.QuadPart - liCounter1.QuadPart) / (double)liFrequency.QuadPart);

 

}


위의 코드를 어셈블리 언어로 변환하는 간단한 방법~



위와 같이 명령 프롬프트에 프로젝트 폴더로 이동하여 cl main.cpp /FAs 라는 명령어를 통해 어셈블리 언어로 변환이 가능하다.




명령어를 수행하면 위와같이 성공적으로 됬단다 라는 말이 나오는데 에러가 있는 부분은 어디어디 에러있으니 고치세요~ 라고 나온다




변환후 폴더에 들어가보면 main.exe, main.asm 이라는 2개의 파일과 object 파일이 생성되는데 뭐 exe파일은 실행이고 asm 파일이 우리가 원하는

어셈블리로 변환된 파일이 되겠다~




변환된 모습~아오 하나도모르겟다 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

빠염~


'Programing > C' 카테고리의 다른 글

어셈블리 c언어 속도측정결과  (0) 2016.11.30
어셈블리와 c언어 속도 비교  (0) 2016.11.30
띄어쓰기까지 입력가능한 scanf  (0) 2016.11.30
데이터형  (0) 2016.11.30
반복문  (0) 2016.11.30

+ Recent posts