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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top