0
//class start--

//Global variable

static PMSK *savepr;
static PRC *prs;

//inside some method

static PMSK wkpm;
PMSK *pm;

if (ipf) {
    k = to_bits(312, &msk);     // This will return k=24 and msk =char(00000001),  
    if ( pm->orbits[k] & msk )  // See the answer of my previous question.
        prs[i].pccused = 1; 
}

For the to_bits method pls see the link

Explain the following C++ method

I am not familiar with C++ coding. What is goin on in the second if block? And explain the variable declarations also?

Thanks

Community
  • 1
  • 1
JavaBits
  • 2,005
  • 11
  • 36
  • 40
  • This does not compile. EDIT: ah, sorry, you wondered about the variable declarations yourself. Yes, they seem to be missing. Where did you find the code? – Christian Severin Apr 07 '11 at 07:30

3 Answers3

2

If I understand you correctly, you wish to know about the if-clause:

if ( pm->orbits[k] & msk ) contains the bitwise-AND operator, which takes the bits of pm->orbits[k] and the bits of msk and returns those bits that were in both values (that's the "AND" part).

For example:
0010 1101 & 1010 1010 = 0010 1000

EDIT: I suggest you read a good beginners C++ book to learn about pointers (the ->) and arrays (the [k]).

Since you gave no information regarding the PMSK type I have no idea what mp->orbits[k] will give you, apart from this: the PMSK struct or class seems to contain an array called orbits, and pm->orbits[24] denotes its 25th (not the 24th!) element.

Christian Severin
  • 1,793
  • 19
  • 38
  • pm->orbits[k] What will this return if the value of K is 24? – JavaBits Apr 07 '11 at 09:47
  • Also what is the meaning of -> operator. Also pm is a type of PMSK , so what does that mean. The rest of the part you explained clearly. – JavaBits Apr 07 '11 at 09:50
  • So inside the if clause it will return true or false ? – JavaBits Apr 07 '11 at 09:51
  • @JavaBits: -> is used for a pointer. It is similar to a '.' but only that it is used for pointers instead of normal variables. pm->orbits[k] means that there is an array named 'orbits' in pm variable. And this is accessing its kth element. – Aamir Apr 07 '11 at 10:20
  • So we can say if PMSK is class and pm is a object which contains an array orbits[]. Am I correct? Thanks for ur suggestions. – JavaBits Apr 08 '11 at 06:00
  • PMSK seems to be a class or struct (these two are more or less the same in C++) which contains an array called orbits, yes. – Christian Severin Apr 08 '11 at 07:44
1
if ( pm->orbits[k] & msk ) // check to see if they aare bit-by-bit identical.

And how the variable declarations are goin on? no idea what you mean, clarify.

Anycorn
  • 50,217
  • 42
  • 167
  • 261
0
class start--

This is invalid syntax.

static PMSK *savepr;
static PRC *prs;

These are pointers to objects of type PMSK, PRC with internal linkage.

static PMSK wkpm;
PMSK *pm;

An instance of object PMSK with internal linkage and a pointer to a PMSK object "wkpm" with translation-unit scope.

    if(ipf){
        k = to_bits(312, &msk);  // you might want to post this "to_bits" function

    if ( pm->orbits[k] & msk )  // this returns the k+1 object in the array "orbits" and performs a bitwise AND with "msk"
// you might want to post the declaration for this pm instance and the class decaration
        prs[i].pccused = 1;  // this sets the member variable "pcussed" of object i + 1 in the array "prs" to 1
}
Maarten
  • 1,037
  • 1
  • 11
  • 32