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


Passing an array of bitfields to a function

Passing an array of bitfields to a function

Passing an array of bitfields to a function


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.

using namespace std;

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

void init(status *coords);

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


//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

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


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! Already a Member? Login


White Paper - A Guide to 3D Printing Materials
When it comes to using an FDM 3D printer effectively and efficiently, choosing the right material at the right time is essential. This 3D Printing Materials Guide will help give you and your team a basic understanding of some FDM 3D printing polymers and composites, their strengths and weaknesses, and when to use them. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close