×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Passing an array of bitfields to a function

Passing an array of bitfields to a function

Passing an array of bitfields to a function

(OP)
Hi,

I was trying to think of a good way to create a battleship game using an array of bitfields, where each point could be 1 byte and would hold all the infomation I need. My program looks like this, but will not compile. Can anyone tell me if what i'm trying to do is impossible/stupid/possible with correct syntax. Thanks.

#include
using namespace std;

struct status {
bool ship :1;
bool shot :1;
};

void init(status *coords);

int main()
{
status coords[10][10];

init(coords);

//test for correct output
cout << coords[0][0].shot << ' ' << coords[0][1].shot;

return 0;
}

void init(status *coords) {
int i, j;
for(i=0; i<10; i++)
for(j=0; j<10; j++) {
coords[i][j].ship = false;
coords[i][j].shot = false;
}
}

RE: Passing an array of bitfields to a function

Hi,
try to declare the parameter of init function with **coords, since it is a 2D array.

cheers

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources