Question:
C:How #include differs from #include?What former means?
electric
2012-10-14 20:59:13 UTC
In my C program using "#include" shows the following error:

"types.h: No such file or directory"

But the error is corrected if I use "#include" instead.

Now I know that "#include" means "Include this header file types.h".But what exactly does "include" mean? My gut feeling (which generally betrays me) tells that "#include" tells the compiler to look for this header file in the parent directory while "#include" tells the compiler to look for the header file in the SUBFOLDER called "sys",ie, inside this sub-folder of parent directory rather than the parent directory(ie parent directory root) itself.So please clear the whole thing for me.
Three answers:
Jonathan
2012-10-14 23:07:16 UTC
It's "implementation-defined." You cannot get around that.



See this section from ISO/IEC 9899:1999:



    6.10.2  Source file inclusion



    Constraints



    1       A #include directive shall identify a header or source file that can be

            processed by the implementation.



    Semantics



    2       A preprocessing directive of the form



                # include new-line



            searches a sequence of implementation-defined places for a header

            identified uniquely by the specified sequence between the < and >

            delimiters, and causes the replacement of that directive by the entire

            contents of the header. How the places are specified or the header

            identified is implementation-defined.



    3       A preprocessing directive of the form



                # include "q-char-sequence" new-line



            causes the replacement of that directive by the entire contents of the

            source file identified by the specified sequence between the " delimiters.

            The named source file is searched for in an implementation-defined

            manner. If this search is not supported, or if the search fails, the directive

            is reprocessed as if it read



                # include new-line



            with the identical contained sequence (including > characters, if any)

            from the original directive.



(Note that "" could search differently than <> and that "" defaults to <> behavior when it fails with its different search.)



In general, I tend to imagine that using <> means that the C compiler will look in directories that it believes are part of the compiler installation. During installation, most set up at least one such "standard directory." Some do more than one. Some compilers (most, actually) also allow you to edit whatever list they start with and to specify more than one additional directory.



In your case, it appears the C compiler only has ONE default place the compiler "knows" about and that it hasn't been informed about the "sys" subdirectory. Most compiler tools permit a command line option to add directories or can otherwise look in special places to get a list of more than one directory that they will automatically use when searching around for a file. The <> means to me that the compiler should look "elsewhere" (not in the current directory where the source code file is located, but in special places it "knows" about where the standard header files should be located.) The "" (quote marks, instead) means to me that the compiler looks in the directory where the source code file is at (in my mind.)



But a C compiler can pack away some special C standard header files in other places (like a subdirectory), keep itself firmly uninformed about that fact, and then insist that you add something extra to actually find it. It's dumb, I know. But where things are at are "implementation-defined." So that is that. The standard says, "How the places are specified or the header identified is implementation-defined." That's life in the big city.



A fix is to modify the compiler you are using so that it automatically looks in the sys subdirectory, too. Or you could set up your own personal #define for each C standard file you want to include, include that file in every source code module, and then use your own "standard" ways of specifying the standard files -- and be able to edit your personal file for any given compiler tool. I think that's going overboard, myself. I just live with it. If the compiler complains, I either look around for a way to add directories into the set it uses and fix it there by adding the 'sys' subdirectory to the list it uses or else I modify the source code I'm working on to fit what the compiler requires. It's not overly-annoying.



Of course, is also pretty normal looking to me. Seen it many times. Never worried much about it. I use when that works and when that works, I suppose. I'd start with and move to the other if that didn't work.
ʄaçade
2012-10-14 21:26:55 UTC
Depending on your operating system implementation.



/usr/include/types.h does not exist on my machine, but /usr/include/sys/types.h does.



Often, /usr/include/types.h itself includes /usr/include/sys/types.h, so they are often nested in an implementation.



It defines some commonly-used types such as pid_t and uid_t.



The <> angle brackets just mean that the usual /usr/include prefix is assumed.
vansant
2016-12-12 13:40:15 UTC
that's like something in existence, on account that all of us do no longer share the comparable attitude and ethical experience we are able to arise with diverse conclusions even whilst analyzing or experiencing the comparable element. i think of all meaning is peace is genuine and it truly is accessed in lots of techniques, that's totally resembling a discern drawing classification. In a room you have people who're drawing the main appropriate comparable variety, even however as quickly as you examine out the photographs everyones rendering of the variety you will see variations. Does that mean the guy has purposefully corrupted the fashions image or in basic terms expressed what they have been experiencing? i might say that's the latter quite than the former, there'll constantly be variety in a international with tens of millions of eyes if each and every person observed each and every thing the comparable way we would all be one individual. All i will grab from that's faith is in basic terms a venue many each and every person is utilising to purpose and locate peace. as properly Google the words "ethical experience" "attractiveness" "love" "discomfort" and that i doubt you have difficulty finding diverse understandings of those as properly. "it form of feels ever perception device has that's very own definition and so referred to as non violent schedule." replace the words "perception device" with "individual" and tell me does the fact lose that's reality? (((Fractal))) beautiful to work out you! Peace and reward =)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...