Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

What does & stands for in C and mmap()

int fd = open("/dev/mem", O_RDWR);
present = (unsigned char *)mmap(0, 
              getpagesize(), 
              PROT_READ|PROT_WRITE, 
              MAP_SHARED, 
              fd, 
              0x22400000);

if ((*present & 1) == 0)
{
  printf("Converter not present
");
  exit(1);
}

1) What does '&' operator mean in the preceding code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is the bitwise and operator. This means that the result of the operation is to perform binary and of the two operands but bit-by-bit (in a bitwise fashion i.e).

In this case it is checking that the first bit of the memory pointed to by present is 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...