不同的结构尺寸 [英] different struct sizes

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

问题描述

我正在使用的JPEG库存在这个奇怪的问题。

是一个被调用的函数,其中一个参数是

传递的是结构的长度。在此函数中,传递的结构的长度

与函数内计算的相同

结构的长度进行比较。现在因为这些值不符合
,程序会退出。


================== ====


这是此函数的原型:

jpeg_CreateDecompress((cinfo),JPEG_LIB_VERSION,q(size_t)sizeof( struct

jpeg_decompress_struct));


======================

现在这是此函数代码的一部分:

GLOBAL(void)jpeg_CreateDecompress(j_decompress_ptr cinfo,int version,

size_t结构化)

{

int i;


/ *防范库和调用者之间的版本不匹配。 * /

cinfo-> mem = NULL; / *所以jpeg_destroy知道mem mgr没有调用

* /

if(version!= JPEG_LIB_VERSION)

ERREXIT2(cinfo,JERR_BAD_LIB_VERSION,JPEG_LIB_VERSION,如果(structsize!= SIZEOF(struct jpeg_decompress_struct))

ERREXIT2(cinfo,JERR_BAD_STRUCT_SIZE,(int)SIZEOF(struct


if jpeg_decompress_struct),(int)structsize);


======================

这是这个函数产生的错误:


JPEG参数struct mismatch:库认为大小是452,调用者

预计404


======================


任何人都有任何想法为什么会发生这样的事情?


谢谢


回复

I have this weird problem with the JPEG library that I am using. There
is a function that is being called and one of the parameters being
passed is the length of a structure. Inside this function, the length
of the structure being passed is compared to the length of the same
structure calculated inside the function. Now because these values do
not match, the program exits.

======================

This is the prototype for this function:

jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, q(size_t) sizeof(struct
jpeg_decompress_struct));

======================

Now this is a portion of this function''s code:

GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
size_t structsize)
{
int i;

/* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called
*/
if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,(int) SIZEOF(struct
jpeg_decompress_struct), (int) structsize);

======================

This is the error produced by this function:

JPEG parameter struct mismatch: library thinks size is 452, caller
expects 404

======================

Would anyone have any idea as to why something like this would happen?

Thanks

Reply

推荐答案

Borked Pseudo Mailed写道:
Borked Pseudo Mailed wrote:

我对我使用的JPEG库有这个奇怪的问题。

是一个被调用的函数,其中一个参数是

传递的是结构的长度。在此函数中,传递的结构的长度

与函数内计算的相同

结构的长度进行比较。现在因为这些值不符合
,程序会退出。


================== ====


这是此函数的原型:

jpeg_CreateDecompress((cinfo),JPEG_LIB_VERSION,q(size_t)sizeof( struct

jpeg_decompress_struct));
I have this weird problem with the JPEG library that I am using. There
is a function that is being called and one of the parameters being
passed is the length of a structure. Inside this function, the length
of the structure being passed is compared to the length of the same
structure calculated inside the function. Now because these values do
not match, the program exits.

======================

This is the prototype for this function:

jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, q(size_t) sizeof(struct
jpeg_decompress_struct));



奇怪的原型......

Odd looking prototype...


======================


现在这是此函数代码的一部分:


GLOBAL(void)jpeg_CreateDecompress(j_decompress_ptr cinfo,int version,

size_t structsize)

{

int i;


/ *防止库和调用者之间的版本不匹配。 * /

cinfo-> mem = NULL; / *所以jpeg_destroy知道mem mgr没有调用

* /

if(version!= JPEG_LIB_VERSION)

ERREXIT2(cinfo,JERR_BAD_LIB_VERSION,JPEG_LIB_VERSION,如果(structsize!= SIZEOF(struct jpeg_decompress_struct))

ERREXIT2(cinfo,JERR_BAD_STRUCT_SIZE,(int)SIZEOF(struct


if jpeg_decompress_struct),(int)structsize);
======================

Now this is a portion of this function''s code:

GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
size_t structsize)
{
int i;

/* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called
*/
if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,(int) SIZEOF(struct
jpeg_decompress_struct), (int) structsize);



什么是SIZEOF()?

What is SIZEOF()?


>

======================


这是这个函数产生的错误:


JPEG参数struct mismatch:库认为大小是452,调用者

预计404


======================


任何人都知道为什么会发生这样的事情?
>
======================

This is the error produced by this function:

JPEG parameter struct mismatch: library thinks size is 452, caller
expects 404

======================

Would anyone have any idea as to why something like this would happen?



让库和你的代码用相同的编译器编译并且

如果使用,对齐选项?


-

Ian Collins。

Have the library and your code been compiled with the same compiler and
if used, alignment options?

--
Ian Collins.


您使用的是库在你以外的平台上编译

使用。您需要为您的平台编译的库(相同硬件

和编译器选项)。


某些平台使用4字节内存作为char和short int

变量。当你在平台上使用1个字节的字符和2个字节的短整数时,会报告这种问题。


问候,

Nagaraj L


11月6日上午6:58,Borked Pseudo Mailed< nob ... @ pseudo.borked.net>

写道:
You are using a library compiled on a platform other than what you are
using. You require libraries compiled for your platform (Same Hardware
and compiler options).

Certain platforms use 4 bytes memory for "char" and "short int"
variables. when you use 1 byte for char and 2 byte for short int on
your platform, this kind of problems are reported.

Regards,
Nagaraj L

On Nov 6, 6:58 am, Borked Pseudo Mailed <nob...@pseudo.borked.net>
wrote:

我正在使用的JPEG库有这个奇怪的问题。

是一个被调用的函数,其中一个参数是

传递的是结构的长度。在此函数中,传递的结构的长度

与函数内计算的相同

结构的长度进行比较。现在因为这些值不符合
,程序会退出。


================== ====


这是此函数的原型:

jpeg_CreateDecompress((cinfo),JPEG_LIB_VERSION,q(size_t)sizeof( struct

jpeg_decompress_struct));


======================

现在这是此函数代码的一部分:

GLOBAL(void)jpeg_CreateDecompress(j_decompress_ptr cinfo,int version,

size_t结构化)

{

int i;


/ *防范库和调用者之间的版本不匹配。 * /

cinfo-> mem = NULL; / *所以jpeg_destroy知道mem mgr没有调用

* /

if(version!= JPEG_LIB_VERSION)

ERREXIT2(cinfo,JERR_BAD_LIB_VERSION,JPEG_LIB_VERSION,如果(structsize!= SIZEOF(struct jpeg_decompress_struct))

ERREXIT2(cinfo,JERR_BAD_STRUCT_SIZE,(int)SIZEOF(struct


if jpeg_decompress_struct),(int)structsize);


======================

这是这个函数产生的错误:


JPEG参数struct mismatch:库认为大小是452,调用者

预计404


======================


任何人都有任何想法为什么会这样呢?


谢谢


回复
I have this weird problem with the JPEG library that I am using. There
is a function that is being called and one of the parameters being
passed is the length of a structure. Inside this function, the length
of the structure being passed is compared to the length of the same
structure calculated inside the function. Now because these values do
not match, the program exits.

======================

This is the prototype for this function:

jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, q(size_t) sizeof(struct
jpeg_decompress_struct));

======================

Now this is a portion of this function''s code:

GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
size_t structsize)
{
int i;

/* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called
*/
if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,(int) SIZEOF(struct
jpeg_decompress_struct), (int) structsize);

======================

This is the error produced by this function:

JPEG parameter struct mismatch: library thinks size is 452, caller
expects 404

======================

Would anyone have any idea as to why something like this would happen?

Thanks

Reply


Nagaraj L< na ****** @ gmail.comwrote:
Nagaraj L <na******@gmail.comwrote:

某些平台使用4字节内存作为char和短整数
Certain platforms use 4 bytes memory for "char" and "short int"



任何使用4字节内存用于char的平台变量是

不符合。 sizeof(char)是1.


-

C. Benson Manica |我*应该*知道我在说什么 - 如果我

cbmanica(at)gmail.com |不,我需要知道。火焰欢迎。

Any platform that uses 4 bytes of memory for "char" variables is
non-conforming. sizeof(char) is 1.

--
C. Benson Manica | I *should* know what I''m talking about - if I
cbmanica(at)gmail.com | don''t, I need to know. Flames welcome.


这篇关于不同的结构尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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