简体   繁体   English

C-内存对齐argv?

[英]C - memory align argv?

I am on Linux, coding in C and tried to play with the align attribute for argv variables, but with no luck : 我在Linux上,用C语言进行编码,并尝试使用argv变量的align属性,但是没有运气:

How could we cause the argv arguments (each of it) to be aligned to a defined boundary, say 16 bits, without copying it first to an aligned variable , via memcpy or alternatives ? 我们如何使argv参数(每个参数)与定义的边界对齐,例如16位, 而无需通过memcpy或替代方法将其首先复制到对齐的变量中

Is it even possible ? 可能吗?

It is not possible. 这不可能。 The align attribute tells the compiler how to align structures for which it generates code and data. align属性告诉编译器如何对齐为其生成代码和数据的结构。 It also tells the compiler about the actual alignment of extern structures and data generated by other code. 它还告诉编译器外部结构和其他代码生成的数据的实际对齐方式。

The argv arguments are supplied by the C startup code or the OS directly. argv参数由C启动代码或操作系统直接提供。 No assumptions should be made about their alignment beyond the implicit self alignment of the pointer array. 除了指针数组的隐式自对齐之外,不应对它们的对齐做任何假设。 You cannot change that with compiler attributes, not is it advisable to force the compiler to make other assumptions. 您不能使用编译器属性来更改它,建议不要强制编译器做出其他假设。

In some implementations, the argv variables can point directly to the original command line where first delimiter (space) after each argument has been replaced with a null. 在某些实现中,argv变量可以直接指向原始命令行,在该命令行中,每个参数后的第一个定界符(空格)已被替换为null。 In such an implementation it is clear that alignement is what it is and cannot be controled ! 在这样的实现中,很明显,对齐就是它,是无法控制的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM