Linux view C structural body definition __linux

Source: Internet
Author: User
Tags first string
Today, when you write a program, you use the Pthread_cond_timedwait function, which is the prototype: int pthread_cond_timedwait (pthread_cond_t  *restrict cond, Pthread_ mutex_t *restrict Mutex, const struct TIMESPEC *restrict abstime); The last parameter is the TIMESPEC structure, but the man did not give a specific definition, had to check it himself. The following is the specific steps, but also for everyone to make a reference, while welcome to provide a better way:

1, the symbol definition is basically in the/usr/include folder can be found under the/USR/SRC (think of their own program referenced in the header file to understand). Then we can search for the structure definition under the/usr/include folder. Enter shell command: grep ' struct timespec '/usr/include/*.h carriage return, observe the result,

From the results (especially the last few lines), we can easily find that the struct Timespec result body is defined in the/usr/include/time.h file.
2, open the Time.h file and view the specific definition. Operation Step: Enter shell command: vi/usr/include/time.h carriage return. Then in the VI editor search struct TIMESPEC can find the specific definition of the structure (vi editor use of immature children's shoes, please consciously google,baidu). As shown in the following illustration:

3, if you look at the specific definition of the struct and you are not satisfied with it, still __time_t this data type in the members of the struct, we continue. Find out what basic data type __time_t is defined by the method of finding the struct TIMESPEC structure. Enter shell command: grep ' __time_t '/usr/include/*.h carriage return, the result is as follows:

Note that the figure is a successful quote: It tells us explicitly: in the/usr/include/bits/types.h file, we define the symbolic __time_t.
4, with the VI editor open file Types.h file, search __time_t, the results are as follows:

At this time, the children's shoes are not a kind of tears running feeling, anyway, I have ... But easy to give up is not our program Ape's smelly temper, with a stubborn strength, continue. The line in the Red Box tells us: __time_t is the number of seconds from Epoch (Epoch:unix timestamp, which represents a specific time: 1970-01-01 00:00:00 UTC, not known to Baidu), and is defined as the standard data type __ Time_t_type, Next, you guessed what I was going to do. Yes, just repeat the steps above to find out what __time_t_type is.
5, enter the shell command: grep ' __time_t_type '/usr/include/.h carriage return, found nothing found. Think carefully, in the fourth step, the Types.h file is under the/usr/include/bits/folder, then its definition is probably right here oh, and then enter the shell command: grep ' __time_t_type '/usr/include/bits/.h Carriage return, the results are as follows: (also can be directly used: grep ' __time_t_type '/usr/include//.h to search this directory and subdirectories, it is recommended that you generally do not search subdirectories, time-consuming AH-multi-layered search grep ' time_t_type ' usr/////*. H

See here, we understand that __time_t_type is defined in the file typesize.h, but we do not need to open the file, notice the following word: __slongword_type says __time_t_type is defined as __slongword _type type. We know that this type of word_type is basically related to the exact number of machine digits. It says: A long type of word on a specific machine.
6, if you want to see what the basic type is on your machine (the machine type is defined in the/usr/include/bits/types.h file), you can enter the shell command: grep ' Slongword_type '/usr/include/bits /types.h Carriage return (if you forget which file, you can search all directories directly: grep ' Slongword_type '/usr/include//.h), the results are as follows:

So far, done, on my machine, __slongword_type is a long int type ...

Added: Vim Editor's search string function;
One, with/and. The difference
/followed by a lookup string. VIM displays the first occurrence of the string in the text.
。 followed by a string to find. VIM displays the last occurrence of the string in the text.
No matter the use/and. After you find the first string, press ENTER, and VIM highlights all the matching strings.
Press N or Shift+n to the next or previous

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.