过程参数结构顺序 [英] procedure parameter struct order

查看:105
本文介绍了过程参数结构顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在混合汇编程序和c代码的时候有
我得到了以下问题:


struct bar {

int bar_val1;

int bar_val2;

(...)

}


void foo(结构栏)

{

DO_SOMETHING;

};

我的问题是,如果堆栈中结构变量的顺序(例如,

bar_val1,bar_val2)在C中定义。


在汇编程序代码中,值应该被推送到堆栈然后

foo应该被调用。我的代码是''为我工作'',但我想知道,如果

它是一个已定义的行为,或者它是特定于gcc的。


thx提前


yoon

Hi, there

while mixing assembler and c code I got the following question:

struct bar {
int bar_val1;
int bar_val2;
(...)
}

void foo(struct bar)
{
DO_SOMETHING;
};
My question is, if the order of the struct vars on the stack (eg.
bar_val1, bar_val2)is defined within C.

In assembler code the values should be pushed onto the stack and then
foo should be called. My code is ''working for me'', but I want to know,if
it is a defined behaviour, or it is gcc specific.

thx in advance

yoon

推荐答案

" Yoon Soo" < Y0 ***** @ gmx.net>在留言中写道

news:c1 ************* @ ID-98218.news.uni-berlin.de ...
"Yoon Soo" <y0*****@gmx.net> wrote in message
news:c1*************@ID-98218.news.uni-berlin.de...
有混合汇编程序和c代码时我得到了以下问题:

结构栏{
int bar_val1;
int bar_val2;
(...)
}

void foo(结构栏)
{
DO_SOMETHING;
};

我的问题是,如果堆栈中结构变量的顺序(例如,
bar_val1,bar_val2)是在C中定义的。
Hi, there

while mixing assembler and c code I got the following question:

struct bar {
int bar_val1;
int bar_val2;
(...)
}

void foo(struct bar)
{
DO_SOMETHING;
};
My question is, if the order of the struct vars on the stack (eg.
bar_val1, bar_val2)is defined within C.




No.标准甚至没有指定堆栈用于参数

传递(实际上,它有时不是)。 呼叫惯例

具体实现。



No. The standards do not even specify that a stack is used for argument
passing at all (and indeed, it sometimes isn''t). The "calling convention" is
implementation specific.


Yoon Soo< y0 ***** @ gmx.net>写道:
Yoon Soo <y0*****@gmx.net> wrote:
在混合汇编程序和c代码时我得到了以下问题:

struct bar {
int bar_val1;
int bar_val2 ;
(...)
}

void foo(结构栏)
{
DO_SOMETHING;
};

我的问题是,如果堆栈中结构变量的顺序(例如
bar_val1,bar_val2)是在C中定义的。
while mixing assembler and c code I got the following question:

struct bar {
int bar_val1;
int bar_val2;
(...)
}

void foo(struct bar)
{
DO_SOMETHING;
};
My question is, if the order of the struct vars on the stack (eg.
bar_val1, bar_val2)is defined within C.




甚至没有定义它们是否在堆栈中开始;例如,
结构可以在几个寄存器中传递。

混合程序集和C深入到依赖于实现的领域

无论如何,如果我是你,我会在新闻组中询问讨论编译器的具体内容。如果你将你的代码绑定到单个

编译器版本中,无论如何通过包含汇编,它不会受到影响

依靠取决于它在它的订单上。但请做文件

你已经做到了这一点。


Richard



It is not even defined whether they are on a stack to begin with; small
structs could be passed in a couple of registers, for example.
Mixing assembly and C is deep into implementation-dependent territory
anyway, so if I were you I''d ask in a newsgroup that discusses the
specifics of your compiler; if you''re tying your code into a single
compiler version anyway by including assembly, it''s not going to hurt to
tie it a bit further by depending on its order. But do document that
you''ve done this.

Richard


Richard Bos写道:
Richard Bos wrote:
我的问题是,如果堆栈中结构变量的顺序(例如,
bar_val1,bar_val2)是在C中定义的。

甚至没有定义它们是否在堆栈中开始;例如,小的
结构可以通过几个寄存器传递。
My question is, if the order of the struct vars on the stack (eg.
bar_val1, bar_val2)is defined within C.

It is not even defined whether they are on a stack to begin with; small
structs could be passed in a couple of registers, for example.




我忘了提,foo是用属性regparm(0)声明的

...这是(afaik)也取决于

编译器的实现,因此在任何情况下都应该使用堆栈。

无论如何,混合程序集和C深入到依赖于实现的领域中,所以如果我是你,我会在新闻组中询问讨论编译器的具体细节;如果您通过包含汇编将代码绑定到单个
编译器版本中,那么根据其顺序将它连接起来并不会有什么坏处。但是做文件说明你已经做到了这一点。



I forgot to mention, that foo is declared with the attribute regparm(0)
... which is (afaik) also depending on the implementation of the
compiler, so the stack should be used in any cases.
Mixing assembly and C is deep into implementation-dependent territory
anyway, so if I were you I''d ask in a newsgroup that discusses the
specifics of your compiler; if you''re tying your code into a single
compiler version anyway by including assembly, it''s not going to hurt to
tie it a bit further by depending on its order. But do document that
you''ve done this.




thx回复。我想我会将一些内联asm代码包含在

foo中,以确保在堆栈中找到正确的参数。


yoon



thx for the replies. I think I will include some inline asm codes into
foo to be sure, that the correct parameters are found on the stack.

yoon


这篇关于过程参数结构顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆