PIC

C30 컴파일러 속성(Attribute) 사용 예제

K :) 2011. 4. 1. 16:04

C 소스 코드

#include <stdio.h> 

// 프로그램 메모리 영역에 상수 위치 시키기 
const unsigned __attribute__ ((space(psv), address(0x2000))) 
    table[10] = {0,1,2,3,4,5,6,7,8,9};

// 데이터 메모리 영역에 변수 위치 시키기 
int __attribute__ ((address(0x900))) x = 5; 

// 프로그램 메모리 영역에 함수 위치 시키기 
int __attribute__ ((address(0x2100))) square(int a);

int main(void) 

    int i, y;

    y = square(x); 
    printf("square = %d\n", y);

    for(i=0;i<10;i++) 
    { 
        printf("table[%d] = %d\n", i, table[i]); 
    } 
    while(1); 


// square 함수 정의 
int square(int a) 

    return (a * a); 
}


결과
Watch창의 Address 필드에 P라고 되어있는 부분은 프로그램 메모리 영역이라는 표시이다.