未定义的问题 [英] Undefined problem

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

问题描述

我所拥有的甚至不是真正的问题,但我希望有人可以帮助

无论如何,但首先是一段代码_


@code start

const unsigned short Size = 2; // 2 ^ N

std :: bitset<尺寸*尺寸*尺寸> YZ;

std :: bitset<尺寸*尺寸*尺寸> XZ;

std :: bitset<尺寸*尺寸*尺寸> XY;

std :: bitset<尺寸*尺寸*尺寸> V;

union {

struct {

unsigned z:8;

unsigned y:8;

unsigned x:8;

};

unsigned id:24;

} coords;

@code结束


有些解释已经到位。


varSize永远是值2 ^ N {1,2,4,8,16,32,64,等等}我还没有找到一种方法,因为当我使用的时候obious解决方案

(pow())编译器不会接受由大小的

我们初始化的位集,非常奇怪。

bitsets只是bitset,不需要解释它们的用途。


联盟有点好,它的机器人有x,y,z coords>

他们自己并有一个爆炸标识符来访问

位集的正确位置。

现在棘手的部分:

我订购这个工作,联盟中的vars必须分配一个

特定数量的内存。

我猜它用一些代码很容易解释:


@code start

union {

struct {

unsigned z:log2(Size );

无符号y:log2(大小);

无符号x:log2(大小);

};

unsigned id:log2(Size)* 3;

} coords;

@code结束


这个当然没有用,但你现在应该明白我的问题了。


问候

Zacariaz

解决方案

fe**********@hotmail.com 写道:

我所拥有的甚至不是真正的问题,但我希望有人可以帮助<无论如何,但首先是一段代码_

@code start
const unsigned short Size = 2; // 2 ^ N
std :: bitset<尺寸*尺寸*尺寸> YZ;
std :: bitset<尺寸*尺寸*尺寸> XZ;
std :: bitset<尺寸*尺寸*尺寸> XY;
std :: bitset<尺寸*尺寸*尺寸> V;
union {
struct {
unsigned z:8;
unsigned y:8;
unsigned x:8;
};
unsigned id:24;
} coords;
@code end

对mig的一些解释到位。

var" Size"永远是价值2 ^ N {1,2,4,8,16,32,64,等等}我还没有找到办法,因为当我使用这个有意义的解决方案时/>(pow())编译器不会接受由大小的
我们初始化的位集,很奇怪。

位集只是bitset,不需要解释什么他们是为了。

这个联盟是有点好的,它作为机器人的方式有x,y,z coords他们自己和有一个爆炸标识符来访问正确的位
bitsets。
现在是棘手的部分:
我命令这个工作,联盟中的变量必须分配特定数量的内存。
我猜用一些代码简单解释:

@code start
union {
struct {
unsigned z:log2(Size);
unsigned y:log2 (大小);
无符号x:log2(大小);
};
无符号id:log2(大小)* 3;
} coords;
@code end

这个课程不起作用,但你应该理解我的问题现在。



模板怎么样:

#include< bitset>


template< unsigned int SizeLog>

struct Labyrinth3D {


static unsigned int const size_log = SizeLog;

static unsigned int const size = 2<< size_log;


std :: bitset<尺寸*尺寸*尺寸> yz;

std :: bitset<尺寸*尺寸*尺寸> xz;

std :: bitset<尺寸*尺寸*尺寸> xy;

std :: bitset<尺寸*尺寸*尺寸> v;


union {


struct {


unsigned x:size_log;

unsigned y:size_log;

unsigned z:size_log;


}虚拟;


unsigned id:3 * size_log;


} coords;


}; // Labyrinth3D<>


Best


Kai-Uwe Bux




< fe ********** @ hotmail.com> skrev i meddelandet

新闻:11 ********************** @ g47g2000cwa.googlegr oups.com ...

我所拥有的甚至不是真正的问题,但我希望有人可以帮助
无论如何,但首先是一段代码_

@code start
const unsigned short大小= 2; // 2 ^ N
std :: bitset<尺寸*尺寸*尺寸> YZ;
std :: bitset<尺寸*尺寸*尺寸> XZ;
std :: bitset<尺寸*尺寸*尺寸> XY;
std :: bitset<尺寸*尺寸*尺寸> V;
union {
struct {
unsigned z:8;
unsigned y:8;
unsigned x:8;
};
unsigned id:24;
} coords;
@code end




这是所有非常实现的定义,意思是完全不可移植。


首先,存入一个工会的一个成员,然后访问

不允许另一个成员!如果你存储一个成员,那个成员是活跃的,而不是其他成员。


在实践中,它可能会起作用,但不保证是什么所以

永远!

接下来,结构中x,y和z的顺序完全是

实现定义,可能的在它们之间填充。


24位无符号也是*非常不寻常的。 :-)


没有保证比无符号有超过16位。它可能只是32,或36,或60,或64,或其他什么。

所以,如果你没有为特定平台编码,使用特定的
编译器版本,以及一些特定的编译器选项,这将只是

无效(除了偶尔,偶然)。 :-)


你到底想要做什么?

Bo Persson



感谢您的回答,请稍后再尝试理解。现在我有一些真正让我感到高兴的东西。

这个编译好了:

@code start

const unsigned short Size = 2;

unsigned short Log2 = 1;

struct something {

unsigned x:Log2;

};

@code结束


这不要:

@code start

const unsigned short Size = 2; // 2 ^ N

unsigned short Log2 = static_cast< const unsigned short>(log2(Size));

struct something {

unsigned x:Log2;

};

@code end

编译错误:`Log2''不能出现在常量表达式中


为什么为什么!!! ????


别误会我的意思,我非常感谢上面的代码,不过我是

仍然非常不经常,我想在

时间迈出一小步。

东西我不明白:

tamplate<>

静态

sizelog和SizeLog有些误导/他们没有价值

以及有关移动位的内容是什么?


问候

Zacariaz


What i have is not even a real problem, but i hope someone can help
anyway, but first a piece of code_

@code start
const unsigned short Size = 2; // 2^N
std::bitset<Size*Size*Size> YZ;
std::bitset<Size*Size*Size> XZ;
std::bitset<Size*Size*Size> XY;
std::bitset<Size*Size*Size> V;
union {
struct {
unsigned z:8;
unsigned y:8;
unsigned x:8;
};
unsigned id:24;
} coords;
@code end

Some explanation migth be in place.

The var "Size" will allways be the value 2^N {1,2,4,8,16,32,64, ect.} i
have yet to find a way to it is, because when i use the obious solution
(pow()) the compiler wont accept the bitsets being initialised by the
us of "Size", wery weird.

The bitsets are just bitset, no need to explain what they are for.

the union is kinda obious, its as way to bot have the x,y,z coords by
them self and have a bombined identifier to access the right bit of the
bitsets.
Now the tricky part:
I order for this to work, the vars in the union have to alocate a
specific amount of memory.
I guess its easyly explained with some code:

@code start
union {
struct {
unsigned z:log2(Size);
unsigned y:log2(Size);
unsigned x:log2(Size);
};
unsigned id:log2(Size)*3;
} coords;
@code end

This ofcourse doesnt work, but you should understand my problem by now.

Regards
Zacariaz

解决方案

fe**********@hotmail.com wrote:

What i have is not even a real problem, but i hope someone can help
anyway, but first a piece of code_

@code start
const unsigned short Size = 2; // 2^N
std::bitset<Size*Size*Size> YZ;
std::bitset<Size*Size*Size> XZ;
std::bitset<Size*Size*Size> XY;
std::bitset<Size*Size*Size> V;
union {
struct {
unsigned z:8;
unsigned y:8;
unsigned x:8;
};
unsigned id:24;
} coords;
@code end

Some explanation migth be in place.

The var "Size" will allways be the value 2^N {1,2,4,8,16,32,64, ect.} i
have yet to find a way to it is, because when i use the obious solution
(pow()) the compiler wont accept the bitsets being initialised by the
us of "Size", wery weird.

The bitsets are just bitset, no need to explain what they are for.

the union is kinda obious, its as way to bot have the x,y,z coords by
them self and have a bombined identifier to access the right bit of the
bitsets.
Now the tricky part:
I order for this to work, the vars in the union have to alocate a
specific amount of memory.
I guess its easyly explained with some code:

@code start
union {
struct {
unsigned z:log2(Size);
unsigned y:log2(Size);
unsigned x:log2(Size);
};
unsigned id:log2(Size)*3;
} coords;
@code end

This ofcourse doesnt work, but you should understand my problem by now.


What about a template:
#include <bitset>

template < unsigned int SizeLog >
struct Labyrinth3D {

static unsigned int const size_log = SizeLog;
static unsigned int const size = 2 << size_log;

std::bitset< size*size*size > yz;
std::bitset< size*size*size > xz;
std::bitset< size*size*size > xy;
std::bitset< size*size*size > v;

union {

struct {

unsigned x:size_log;
unsigned y:size_log;
unsigned z:size_log;

} dummy;

unsigned id:3*size_log;

} coords;

}; // Labyrinth3D<>

Best

Kai-Uwe Bux



<fe**********@hotmail.com> skrev i meddelandet
news:11**********************@g47g2000cwa.googlegr oups.com...

What i have is not even a real problem, but i hope someone can help
anyway, but first a piece of code_

@code start
const unsigned short Size = 2; // 2^N
std::bitset<Size*Size*Size> YZ;
std::bitset<Size*Size*Size> XZ;
std::bitset<Size*Size*Size> XY;
std::bitset<Size*Size*Size> V;
union {
struct {
unsigned z:8;
unsigned y:8;
unsigned x:8;
};
unsigned id:24;
} coords;
@code end



This is all very implementation defined, meaning totally non-portable.

First of all, storing into one member of a union, and then accessing
another member is not allowed! If you store one member, that member is
active and none of the others.

In practice, it just might work, but there are no guarantees what so
ever!
Next, the order of x, y, and z in your struct is totally
implementation defined, as is the possible padding between them.

Having a 24 bit unsigned is also *highly* unusual. :-)

There are no guarantees than an unsigned has more than 16 bits. It
might just as well be 32, or 36, or 60, or 64, or whatever.
So, if you don''t code for a specific platform, with a specific
compiler version, and some specific compiler options, this will just
not work (except sometimes, by chance). :-)

What exactly are you trying to do here??
Bo Persson



Thanks for the answer, ill try and understand it later. For now i have
something that really enoys me.
This compiles fine:
@code start
const unsigned short Size = 2;
unsigned short Log2 = 1;
struct something {
unsigned x:Log2;
};
@code end

This dont:
@code start
const unsigned short Size = 2; // 2^N
unsigned short Log2 = static_cast<const unsigned short>(log2(Size));
struct something {
unsigned x:Log2;
};
@code end
Compiler error: `Log2'' cannot appear in a constant-expression

Why why why!!!????

Dont get me wrong, im very thankfull for the code above, however i am
still very unexoerienced and i would like to take a little step at the
time.
Stuff i dont understand:
tamplate<>
static
sizelog and SizeLog is some how misleading/they have no value
and whats about the moving bits stuff?

Regards
Zacariaz


这篇关于未定义的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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