重载的供应商库例程:这是C ++吗?还是非常聪明的C? [英] Overloaded vendor library routine: is this C++? Or very clever C?

查看:45
本文介绍了重载的供应商库例程:这是C ++吗?还是非常聪明的C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一些使用

第三方供应商库的未记录功能的代码。从本质上讲,这个供应商保留了接口结构秘密的

细节,但是我们可以将指向这个结构的指针传递给其他供应商例程。该结构描述了一个复杂的时间变量对象,但它基本上归结为一个整数,并且

有访问例程来获取该整数的当前值。


我的问题是:


1)我们的代码是C,而我认为供应商的库也是C


2)这个未记录的功能允许我(前)同事的代码直接从指针读取整数
整数。换句话说,返回

值会以某种方式超载。


这怎么可能?我唯一的想法是供应商库实际上是C ++,但即使它是,我仍然看不出如何使这个

工作。


这是一个测试程序,显示这个(它编译好单独的

例程):


#include< stdio.h>


typedef struct dummyTag * dummy; //秘密供应商结构

extern dummy bar(void); //供应商的访问例程

void foo(void){

int wibble;

wibble =(long)酒吧(); //应该不可能,但是......

printf(wibble is%d \ nn,wibble); //作品!!

}


这可能在C?或者供应商库是否必须是C ++?如果

它是C ++,这是如何工作的?我正在使用gcc进行编译,我无法看到这个模块如何与一个带有过载

访问例程的C ++类接口。


杰克

I''ve inherited some code which uses an undocumented feature of a
third-party vendor''s library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer to
this struct to other vendor routines. The struct describes a complex
time-varying object, but it basically boils down to an integer, and
there are access routines to get to the current value of this integer.

My problem is:

1) Our code is C, and the vendor''s library is, I think, also C

2) This undocumented feature allowed my (ex) colleague''s code to read
the integer directly from the pointer. In other words, the return
value is somehow overloaded.

How is this possible? My only thought is that the vendor library is
actually C++, but even if it is, I still can''t see how to make this
work.

Here''s a test program that shows this (it compiles Ok as a stand-alone
routine):

#include <stdio.h>

typedef struct dummyTag * dummy; // secret vendor struct

extern dummy bar(void); // vendor''s access routine

void foo(void) {
int wibble;
wibble = (long)bar(); // shouldn''t be possible, but...
printf("wibble is %d\n", wibble); // works!!
}

Is this possible in C? Or does the vendor library have to be C++? If
it is C++, how does this work? I''m compiling with gcc and I can''t see
how this module could interface with a C++ class with overloaded
access routines.

Many thanks -

Jack

推荐答案

[后续设置对于comp.lang.c]


杰克戴利说:
[Followups set to comp.lang.c]

Jack Daly said:
我继承了一些使用<无法记录的<第三方供应商的库。从本质上讲,这个供应商已经保持了接口结构的详细信息,但是我们可以将指向这个结构的指针传递给其他供应商例程。结构描述了一个复杂的时变对象,但它基本上归结为一个整数,并且有访问例程来获取该整数的当前值。


简而言之,你有一个不透明的类型。到目前为止一直很好。

我的问题是:

1)我们的代码是C,而我认为供应商的库也是C


这不是问题。那是一个机会。 :-)

2)这个未记录的功能允许我(前)同事的代码直接从指针读取整数。换句话说,返回
值会以某种方式超载。


嗯,也许有一个更简单的解释。


这怎么可能?我唯一的想法是供应商库实际上是C ++,但即使是这样,我仍然看不到如何使这个工作。

这里''一个测试程序,显示这个(它编译为一个独立的例程):

#include< stdio.h>

typedef struct dummyTag *假; //秘密供应商结构

extern虚拟条(无效); //供应商的访问例程

void foo(void){
int wibble;
wibble =(long)bar(); //应该不可能,但是......
printf(wibble is%d \ nn,wibble); //工作!!


好​​吧,你所做的是将指针转换成一个整数,如果你投了它,那就是
合法。结果信息通常很有意义,但你似乎认为你得到的价值有意义。

是什么让你这么想?


如果这真的是秘密结构存储的值,那么大概是

它写成这样的东西:


dummy酒吧(无效)

{

返回(虚拟)秘密号码;

}

}
<这可能在C?
I''ve inherited some code which uses an undocumented feature of a
third-party vendor''s library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer to
this struct to other vendor routines. The struct describes a complex
time-varying object, but it basically boils down to an integer, and
there are access routines to get to the current value of this integer.
In short, you have an opaque type. So far so good.
My problem is:

1) Our code is C, and the vendor''s library is, I think, also C
That''s not a problem. That''s an opportunity. :-)
2) This undocumented feature allowed my (ex) colleague''s code to read
the integer directly from the pointer. In other words, the return
value is somehow overloaded.
Well, perhaps there is a simpler explanation.

How is this possible? My only thought is that the vendor library is
actually C++, but even if it is, I still can''t see how to make this
work.

Here''s a test program that shows this (it compiles Ok as a stand-alone
routine):

#include <stdio.h>

typedef struct dummyTag * dummy; // secret vendor struct

extern dummy bar(void); // vendor''s access routine

void foo(void) {
int wibble;
wibble = (long)bar(); // shouldn''t be possible, but...
printf("wibble is %d\n", wibble); // works!!
Well, what you''ve done is converted a pointer into an integer, which is
legal if you cast it. The resulting information is normally pretty
meaningless, but you seem to think there is meaning in the value you get.
What makes you think that?

If that really is the value that the secret struct stores, then presumably
it''s written something like this:

dummy bar(void)
{
return (dummy)secretnumber;
}
}

Is this possible in C?




我不认为你已经确定发生了超载。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



I don''t think you''ve yet established that overloading is occurring.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Jack Daly写道:
Jack Daly wrote:

我继承了一些使用
第三方供应商库的未记录功能的代码。从本质上讲,这个供应商已经保持了接口结构的详细信息,但是我们可以将指向这个结构的指针传递给其他供应商例程。结构描述了一个复杂的时变对象,但它基本上归结为一个整数,并且有访问例程来获取该整数的当前值。
2)这个未记录的功能允许我(前)同事的代码直接从指针读取整数。换句话说,返回
值会以某种方式超载。

这怎么可能?

I''ve inherited some code which uses an undocumented feature of a
third-party vendor''s library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer to
this struct to other vendor routines. The struct describes a complex
time-varying object, but it basically boils down to an integer, and
there are access routines to get to the current value of this integer. 2) This undocumented feature allowed my (ex) colleague''s code to read
the integer directly from the pointer. In other words, the return
value is somehow overloaded.

How is this possible?




如果我有一个结构

我可以直接从结构的指针读取一个整数,

这意味着与你描述的不同,

我剪了。


如果你将一个struct

的地址转换为指向它的第一个成员类型的指针,

然后该结果将是指向结构的第一个成员的指针。

如果第一个成员是一个整数,那么

那就是我的意思能够直接从指向结构的指针访问
一个整数。


我正在从clc读这个交叉点。


-

pete



If I had a struct
where I could read an integer directly from a pointer to the struct,
it would mean something different from what you described,
which I snipped.

If you convert the address of a struct
to a pointer to the type of it''s first member,
then that result will be a pointer to the first member of the struct.
If that first member were an integer,
then that''s what I would mean by being able to access
an integer directly from a pointer to the struct.

I''m reading this crosspost from clc.

--
pete


On Sun,2006年5月14日12:47:05 GMT,pete< pf * ****@mindspring.com>写道:
On Sun, 14 May 2006 12:47:05 GMT, pete <pf*****@mindspring.com> wrote:
如果你将一个结构的地址转换为一个指向它的第一个成员类型的指针,那么那个结果将是一个指向结构的第一个成员的指针。
如果第一个成员是一个整数,那么这就是我能够直接从指针访问一个整数的意思结构。


嗯..但代码转换为长而不是很长*:

void foo(void){
int wibble;
wibble =(长)bar(); //应该不可能,但是......
printf(wibble is%d \ nn,wibble); //作品!!
}
If you convert the address of a struct
to a pointer to the type of it''s first member,
then that result will be a pointer to the first member of the struct.
If that first member were an integer,
then that''s what I would mean by being able to access
an integer directly from a pointer to the struct.
Hmmm.. but the code casts to a long, rather than a long*:
void foo(void) {
int wibble;
wibble = (long)bar(); // shouldn''t be possible, but...
printf("wibble is %d\n", wibble); // works!!
}




如果这是C,那么printf应该打印一个地址,但它是

实际打印(从内存,4次调用)2,18,0,0,这是

正是我对这4个VHDL信号的期望,这两个信号是两个

整数值为2和18,两个布尔值为false。


所以,我不认为它可以是C,甚至是错误的C.另一方面,我没有看到它是怎样的C ++,原因有两个:


1 - 这个编译单元中没有任何内容描述了

''struct dummyTag''的内部结构。我不认为这是可能的

C ++ - 在编译这个文件时编译器不需要知道,

''struct dummyTag''是一个可以读取返回长的类?


2 - 我看不出如何用gcc编译,而不是g ++。

谢谢 -


杰克



If this was C, then the printf should be printing an address, but it
actually prints (from memory, for 4 calls) 2, 18, 0, 0, which is
exactly what I''d expect for these 4 VHDL signals, which are two
integers with values 2 and 18, and two booleans with value false.

So, I don''t think it can be C, even buggy C. On the other hand, I
don''t see how it can be C++, for 2 reasons:

1 - this compilation unit includes nothing which describes the
internals of ''struct dummyTag''. I didn''t think this was possible in
C++ - doesn''t the compiler need to know, when compiling this file,
that ''struct dummyTag'' is a class which can be read to return a long?

2 - I can''t see how I can compile with gcc, rather than g++.

Thanks -

Jack


这篇关于重载的供应商库例程:这是C ++吗?还是非常聪明的C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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