Re: C Interview Questions



Keith Thompson wrote:

If a header contains a function definition, and that header is
included in two or more translation units in the same program, Bad
Things Could Happen. (I'm too lazy to figure out whether it's
undefined behavior, a constraint violation, or whatever.)

Bad things don't happen if the function definitions are static,
or if it is C99 and they are inline

.



Relevant Pages

  • Re: [opensuse] Linking problem with g++ [off topic]
    ... Bogdan Cristea wrote: ... and use the header XP_class.h into another file xml_parser.cpp to ... Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org ...
    (SuSE)
  • Re: including files
    ... (I want to use some functions of the included file, which is not the "main" function, can I just declare the functions I want to use only at the header). ... void f; // declaration, no definition ... That way you can be sure that the prototype matches the actual function definition. ...
    (microsoft.public.vc.language)
  • Re: error: implicit declaration of function `func_name
    ... The actual function definition is in /source/folderB/fileB.c. ... warning: implicit declaration of function `func_name' ... Include the correct prototype for func_name in a header and include ...
    (comp.lang.c)
  • Re: Global variables
    ... static unsigned char v2; ... Referring to 'v1' it means that I have to include the header only one time and then every time I need to use the variable 'v1' in other translation unit I just use 'extern char v1' and then every operation on 'v1' will update the one and only 'v1' variable right? ... Headers may contain declarations of variables but not ever definitions. ... Avoiding definitions allows you to #include the header in any or all of you .c translation units. ...
    (comp.lang.c)
  • Re: Global variables
    ... Then include the header file in some unit. ... translation unit I just use 'extern char v1' and then every operation ... If you include the header in two or more translation units ... void init; ...
    (comp.lang.c)