位置:51电子网 » 技术资料 » D S P

ADS下C语言中局部变量的存储位置分配

发布时间:2008/8/25 0:00:00 访问次数:666

  按照一般教科书上的说法,c语言中的局部变量应该是分配在"栈"中的。而实际情况,有些出入录,肯能更容易理解。

  这一段代码,唯一的用途,就是分配变量。

int func1(void)
{
    volatile int father;
    volatile int mother;
    volatile int boy;
    volatile int girl;
    father = 30;
    mother = boy = girl = father;
    return father;
}
int func2(void)
{
    volatile int father;
    volatile int mother;
    volatile int boy;
    volatile int girl;
    volatile int unnecessary;
    father = 30;
    mother = boy = girl = father;
    unnecessary = 0;
    return father;
}
int func3(void)
{
    volatile int stone[2];
    stone[0] = 30;
    return stone[0];
}
int func4(void)
{
    volatile int stone[2];
    stone[0] = 30;
    if(stone[0] == 30)
    {
        volatile int father;
        father = 91;
    }    
    else
    {
        volatile int mother;
        mother = 90;
    }
    return stone[0];
}
int func5(void)
{
    volatile int stone[2];
    stone[0] = 30;
    if(stone[0] == 30)
    {
        volatile int boy[2];
        boy[0] = 91;
    }    
    else
    {
        volatile int girl[2];
        girl[0] = 90;
    }
    return stone[0];
}
int func10(int a, int b, int c, int d)
{
    return a + b + c + d;
}
int func11(int a, int b, int c, int d)
{
    volatile int father = a;
    volatile int mother = b;
    volatile int boy = c;
    volatile int girl = d;
    return father + mother + boy + girl;
}
typedef struct home
{
    int father;
    int mother;
} thome;
int func12()
{
    thome home;
    home.father= 12;
    home.mother = 12;
    return home.father + home.mother;
}
typedef int uint32;
int func13()
{
    uint32 home = 2;
    home *= 2;
     
		 

  按照一般教科书上的说法,c语言中的局部变量应该是分配在"栈"中的。而实际情况,有些出入录,肯能更容易理解。

  这一段代码,唯一的用途,就是分配变量。

int func1(void)
{
    volatile int father;
    volatile int mother;
    volatile int boy;
    volatile int girl;
    father = 30;
    mother = boy = girl = father;
    return father;
}
int func2(void)
{
    volatile int father;
    volatile int mother;
    volatile int boy;
    volatile int girl;
    volatile int unnecessary;
    father = 30;
    mother = boy = girl = father;
    unnecessary = 0;
    return father;
}
int func3(void)
{
    volatile int stone[2];
    stone[0] = 30;
    return stone[0];
}
int func4(void)
{
    volatile int stone[2];
    stone[0] = 30;
    if(stone[0] == 30)
    {
        volatile int father;
        father = 91;
    }    
    else
    {
        volatile int mother;
        mother = 90;
    }
    return stone[0];
}
int func5(void)
{
    volatile int stone[2];
    stone[0] = 30;
    if(stone[0] == 30)
    {
        volatile int boy[2];
        boy[0] = 91;
    }    
    else
    {
        volatile int girl[2];
        girl[0] = 90;
    }
    return stone[0];
}
int func10(int a, int b, int c, int d)
{
    return a + b + c + d;
}
int func11(int a, int b, int c, int d)
{
    volatile int father = a;
    volatile int mother = b;
    volatile int boy = c;
    volatile int girl = d;
    return father + mother + boy + girl;
}
typedef struct home
{
    int father;
    int mother;
} thome;
int func12()
{
    thome home;
    home.father= 12;
    home.mother = 12;
    return home.father + home.mother;
}
typedef int uint32;
int func13()
{
    uint32 home = 2;
    home *= 2;
     
		 
	     
	   
相关IC型号
版权所有:51dzw.COM
深圳服务热线:13692101218  13751165337
粤ICP备09112631号-6(miitbeian.gov.cn)
公网安备44030402000607
深圳市碧威特网络技术有限公司
付款方式


 复制成功!