这个功能有什么回报! [英] What does this function return!

查看:54
本文介绍了这个功能有什么回报!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define UWORD2 unsigned short int

typedef BYTE Boolean;

Boolean evaluateBit(UWORD2 * value,int bitnumber);

Boolean evaluateBit (UWORD2 * value,int bitnumber){

int one = 1;

return(one&(* value> bitnumber));

}


当我这样调用函数时:


#include< stdlib.h>

#define UWORD2 unsigned short int

typedef BYTE Boolean;

Boolean evaluateBit(UWORD2 * value,int bitnumber);

int main(void ){

布尔岛;

int row = 15;

int col = 15;

int i, j;

float qual [row] [col];

/ *另一个函数将值赋给qual并同时施放

他们漂浮* /

/ *以下浮动值被重新编号为unsigned char,然后才发送给函数* /

for(i = 0; i< col; i ++){

for(j = 0; j< row; j ++){

island = evaluateBit ((unsigned char)& qual [i] [j],4);

}

}

return(1)

}


布尔值evaluateBit(UWORD2 *值,int位数){

int one = 1;

return(1&(* value> bitnumber));

}


我收到以下警告:

警告:传递`evaluateBit'的arg 1'使得整数指针

没有演员阵容


我不理解返回语句和发生此警告的原因。

提前致谢,

谢尔顿

解决方案
"谢尔顿" < sh ****** @ gmail.comwrites:


请使用缩进。


#include< ;文件stdlib.h>



#include< limit.h>


#define UWORD2 unsigned short int

typedef BYTE布尔值;



BYTE未定义


Boolean evaluateBit(UWORD2 * value,int bitnumber);



char evaluateBit(unsigned char * value,unsigned bitnumber){


int main(void){

布尔岛;

int row = 15,col = 15;

int i,j;

浮动qual [row] [col];

/ *另一个函数将值赋给qual并同时

将它们转换为浮动* /
$ b $

被发送到函数* /

for(i = 0; i< col; i ++){<之前b / *浮点值以下被重新编号为unsigned char br />
for(j = 0; j< row; j ++){

island = evaluateBit((unsigned char)& qual [i] [j],4);



evaluateBit需要一个指向unsigned short的指针而不是
一个unsigned char值。你想要的是:


island = evaluateBit((unsigned short *)& qual [i] [j],4);


但是仍然可能存在一些问题。您应该使用:


island = evaluateBit((unsigned char *)& qual [i] [j],4);


并更改evaluateBit函数。


BTW。我希望你打算和岛上做点什么。


}

}

返回1



您确定要返回1吗?


}


Boolean evaluateBit(UWORD2 * value,int bitnumber){

int one = 1;

return(one&(* value> bitnumber));

}



试试这个:


char evaluateBit(unsigned char * value,unsigned bitnumber){

return(值[bitnumber / CHAR_BIT]>(bitnumber%CHAR_BIT))& 1;

}


我收到以下警告:

"警告:传递arg 1的` evaluateBit''从整数制作指针

没有演员表'


我不理解return语句



哪个退货单?


以及出现此警告的原因。



我希望我已经解释过了。


-

祝你好运, _ _

.o。 | Serenly Enlightened Majesty of o'',=。/`o

..o |计算机科学,Michalmina86 Nazarewicz(oo)

ooo + - < mina86 * tlen.pl> ---< jid:mina86 * chrome.pl> - ooO - (_) - Ooo--


在文章< 11 ********************** @ b28g2000cwb.googlegroups .com>中,

Sheldon< sh ****** @ gmail.comwrote:


> island = evaluateBit(( unsigned char)& qual [i] [j],4);


> Boolean evaluateBit(UWORD2 * value,int bitnumber){


>我收到以下警告:
"警告:传递`evaluateBit'的arg 1'使得整数指针
没有强制转换


>我不理解return语句以及为什么会出现此警告。



注意岛屿=你在哪里调用evaluateBit的作业。

你拿& qual [i] [j]然后把它投到(unsigned char)。

unsigned char不是指针,但evaluateBit需要一个指针

作为它的第一个参数。


可能你想要演绎(unsigned char *)


-

那时候我还很年轻,但我也很朦胧。 br />
- Christopher Priest


Sheldon< sh ****** @ gmail.comwrote:

浮动值以下的
/ *被重新编号为unsigned char,然后发送给函数* /

for(i = 0; i< col; i ++){

for(j = 0; j< row; j ++){

island = evaluateBit((unsigned char)& qual [i] [j ],4);



与您的评论所说的相反,您不会施放浮动值,

您投下地址。然后你把一个转换地址(它现在是一个unsigned int类型的
)传递给一个函数,该函数需要一个地址

作为它的第一个参数,正如编译器告诉的那样你用


"警告:传递`evaluateBit'的arg 1'使得整数指针

没有强制转换



因为你不能取表达式的地址(即

''(unsigned int)qual [i] [j]''你实际上似乎想要使用),

你需要一个额外的变量来存储演员的结果和

然后将它的地址传递给你的函数:


for(i = 0; i< col; i ++){

for(j = 0; j< row; j ++){

unsigned int val =(unsigned int)qual [i] [j];

island = evaluateBit(& val,4);

}

}


当然,如果你只是改变你的

函数来取一个unsigned int就可以变得更简单了它的第一个参数是

的地址...

问候,Jens

-

\ Jens Thoms Toerring ___ jt@toerring.de

\ __________________________ http://toerring.de


#define UWORD2 unsigned short int
typedef BYTE Boolean;
Boolean evaluateBit(UWORD2 *value, int bitnumber);
Boolean evaluateBit(UWORD2 *value, int bitnumber) {
int one=1;
return (one &(*value >bitnumber));
}

When I call the function like this:

#include <stdlib.h>
#define UWORD2 unsigned short int
typedef BYTE Boolean;
Boolean evaluateBit(UWORD2 *value, int bitnumber);
int main(void) {
Boolean island;
int row=15;
int col=15;
int i,j;
float qual[row][col];
/* another function assigns values to qual and at the same time casts
them to float */
/* below the float values are recasted to unsigned char before being
sent to the function */
for (i=0;i<col;i++){
for (j=0;j<row;j++){
island = evaluateBit((unsigned char)&qual[i][j],4);
}
}
return (1)
}

Boolean evaluateBit(UWORD2 *value, int bitnumber) {
int one=1;
return (one &(*value >bitnumber));
}

I get the following warning:
"warning: passing arg 1 of `evaluateBit'' makes pointer from integer
without a cast"

I don''t understand the return statement and why this warning occurs.

Thanks in advance,
Sheldon

解决方案

"Sheldon" <sh******@gmail.comwrites:

Please, use indention.

#include <stdlib.h>

#include <limit.h>

#define UWORD2 unsigned short int
typedef BYTE Boolean;

BYTE is undefined

Boolean evaluateBit(UWORD2 *value, int bitnumber);

char evaluateBit(unsigned char *value, unsigned bitnumber) {

int main(void) {
Boolean island;
int row = 15, col = 15;
int i, j;
float qual[row][col];
/* another function assigns values to qual and at the same time
casts them to float */
/* below the float values are recasted to unsigned char before
being sent to the function */
for (i = 0; i<col; i++) {
for (j = 0; j<row; j++) {
island = evaluateBit((unsigned char)&qual[i][j],4);

evaluateBit expects a pointer to unsigned short instead it gets
an unsigned char value. What you want is:

island = evaluateBit((unsigned short*)&qual[i][j], 4);

but still there may be some problems with that. You should rather use:

island = evaluateBit((unsigned char*)&qual[i][j], 4);

and change evaluateBit function.

BTW. I do hope you intend to do something with island.

}
}
return 1

Are you sure you want to return 1?

}

Boolean evaluateBit(UWORD2 *value, int bitnumber) {
int one = 1;
return (one &(*value >bitnumber));
}

Try this one:

char evaluateBit(unsigned char *value, unsigned bitnumber) {
return (value[bitnumber / CHAR_BIT] >(bitnumber % CHAR_BIT)) & 1;
}

I get the following warning:
"warning: passing arg 1 of `evaluateBit'' makes pointer from integer
without a cast"

I don''t understand the return statement

Which return statement?

and why this warning occurs.

I hope I''ve explained that.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o'' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--


In article <11**********************@b28g2000cwb.googlegroups .com>,
Sheldon <sh******@gmail.comwrote:

>island = evaluateBit((unsigned char)&qual[i][j],4);

>Boolean evaluateBit(UWORD2 *value, int bitnumber) {

>I get the following warning:
"warning: passing arg 1 of `evaluateBit'' makes pointer from integer
without a cast"

>I don''t understand the return statement and why this warning occurs.

Notice the island = assignment where you call evaluateBit.
You take &qual[i][j] and you cast that to (unsigned char).
An unsigned char is not a pointer, but evaluateBit needs a pointer
for its first argument.

Possibly you wanted to cast to (unsigned char*)

--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


Sheldon <sh******@gmail.comwrote:

/* below the float values are recasted to unsigned char before being
sent to the function */
for (i=0;i<col;i++){
for (j=0;j<row;j++){
island = evaluateBit((unsigned char)&qual[i][j],4);

Contrary to what your comment says you don''t cast the float value,
you cast its address. And then you pass the cast address (which has
now a type of unsigned int) to a function that expects an address
as its first argument, exactly as the compiler tells you with

"warning: passing arg 1 of `evaluateBit'' makes pointer from integer
without a cast"

Since you can''t take the address of of an expression (i.e. the
''(unsigned int) qual[i][j]'' you actually seem to want to use),
you need an extra variable to store the result of the cast and
then pass its address to your function:

for (i = 0; i < col; i++) {
for (j = 0; j < row; j++) {
unsigned int val = (unsigned int) qual[i][j];
island = evaluateBit(&val, 4);
}
}

Of course, it could get simpler if you would just change your
function to take an unsigned int as its first argument instead
of an address...
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de


这篇关于这个功能有什么回报!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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