I am new to C -code but I notice that when a variable name is related to its function it makes it easier to read the code to see what it does.
So for instance I have learned from this forum that buf is short for buffer. Seems quite reasonable. But often in code I am seeing 'fd' used.
From reading I gather that fd means file descriptor.
Sometimes when there is an actual fopen or other file related function I understand why they use fd for variable name.
But when it is used for special system character devices I wonder why.
Here is an example:
So this opens the hardware character device for use and has an integer data type.
Why would you use fd as the variable name.
Obviously you could name it anything you want but we do have standard coding conventions.
Why fd for a character device variable name. I know /dev/gpiochip0 is a file but not a normal file but special, right?
This snippet was not taken from FreeBSD code but some examples I am working with.
Like I say you could name it anything but fd seems hard to read the code with.
So for instance I have learned from this forum that buf is short for buffer. Seems quite reasonable. But often in code I am seeing 'fd' used.
From reading I gather that fd means file descriptor.
Sometimes when there is an actual fopen or other file related function I understand why they use fd for variable name.
But when it is used for special system character devices I wonder why.
Here is an example:
Code:
int fd = open("/dev/gpiochip0", 0);
Why would you use fd as the variable name.
Obviously you could name it anything you want but we do have standard coding conventions.
Why fd for a character device variable name. I know /dev/gpiochip0 is a file but not a normal file but special, right?
This snippet was not taken from FreeBSD code but some examples I am working with.
Like I say you could name it anything but fd seems hard to read the code with.