don't understand declaration "unsigned int ip_v:4"

J

jian

Hi,

I am looking at netinet/ip.h in linux code, and the declaration:
unsigned int ip_hl:4 make me confused.

I can understand "unsigned int ip_hl", but, what does ":4" here mean?

Very grateful to any answer.

Jian
 
J

James Hu

I am looking at netinet/ip.h in linux code, and the declaration:
unsigned int ip_hl:4 make me confused.

I can understand "unsigned int ip_hl", but, what does ":4" here mean?

This kind of syntax is only allowed for a union or struct field, and
declares a bit-field. In this case, it is declaring ip_hl to hold
values that fit in 4 bits.

-- James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,065
Members
48,770
Latest member
ElysaD

Latest Threads

Top