C++ C+中typedef结构的混淆+;

C++ C+中typedef结构的混淆+;,c++,arrays,bitmask,C++,Arrays,Bitmask,我有一个我的教授写的程序,模拟内存写入二级缓存的方式。它有几个地方我应该填空。我要做的第一件事是清除每个缓存项的有效位。他给了我们以下信息: //number of cache entries (2^11) #define L2_NUM_CACHE_ENTRIES (1<<11) /*************************************************** This struct defines the structure of a single c

我有一个我的教授写的程序,模拟内存写入二级缓存的方式。它有几个地方我应该填空。我要做的第一件事是清除每个缓存项的有效位。他给了我们以下信息:

//number of cache entries (2^11)

#define L2_NUM_CACHE_ENTRIES (1<<11)

/***************************************************

This struct defines the structure of a single cache
entry in the L2 cache. It has the following fields:
v_d_tag: 32-bit unsigned word containing the
valid (v) bit at bit 31 (leftmost bit),
the dirty bit (d) at bit 30, and the tag
in bits 0 through 15 (the 16 rightmost bits)
cache_line: an array of 8 words, constituting a single
cache line.
****************************************************/

Typedef struct {

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

} L2_CACHE_ENTRY;

//The L2 is just an array cache entries

L2_CACHE_ENTRY l2_cache[L2_NUM_CACHE_ENTRIES];
//缓存条目的数量(2^11)

定义了L2SUnnMyCaseEx条目(1<P>TyPulfStruts是C++中的冗余,如<代码>定义> <代码>,它们可以是静态const int。< /p> 为了清除它们,您需要执行以下操作

for(int i = 0; i < L2_NUM_CACHE_ENTRIES; i++)
    l2_cache[i].v_d_tag &= 0x80000000;
for(int i=0;i< C/>代码> 

结构是以C方式定义的,因为在C中,TyPuff声明结构是一个常见的习惯用法,因此它可以被用作一种类型,而不必在每个引用上编写“代码>结构2L2CaseEnEng/<代码>。C++中不再需要这个习语,因为Stult标签将作为一个单独的类型工作。 简而言之,C++中你可以处理< /P>

typedef struct {

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

} L2_CACHE_ENTRY;
一模一样

struct L2_CACHE_ENTRY{

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

};

你的问题和你的标题有什么关系?嗯,我很确定我对代码的不理解与typedef设置有关,我不知道如何将我问题的细节简洁地表达成标题,所以我同意了。对不起,如果我违反了礼仪,那不是我的意图,我只是不知道该怎么做是的,但根本没有回答这个问题。