Note that there are some explanatory texts on larger screens.

plurals
  1. POdifference in including header in .cpp and .h
    primarykey
    data
    text
    <p>I have a code in which I <code>#include&lt;linux/videodev2.h&gt;</code>. There are three files:</p> <ol> <li><p>one header file- includes: <code>stdint.h</code> and <code>stdlib.h</code>. Defines a couple of functions, a struct, say abc, and some #define macros. One of the functions is</p> <pre><code>int func(int, uint32_t, size_t, abc*); </code></pre></li> <li><p>one cpp file with a lot of methods, including definition of the functions in the .h file.</p></li> <li><p>one main.cpp which has main() which has a function call to the method in the .h file (complete file below). This file is only for testing purposes.</p> <pre><code>#include "head.h" int main() { func(5, (uint32_t)5, (size_t)5, 0); return 0; } </code></pre></li> </ol> <p>What is see is a curious case:</p> <ol> <li>If I include <code>linux/videodev2.h</code> only in .h file, <code>uint32_t</code> and other things defined in this header are not accessible by the .cpp files. (erros I get are: <code>uint32_t was not declared in this scope</code>, and <code>uint32_t does not name a type</code>, among others). This happens even if the first line of the .h file is <code>#include&lt;linux/videodev2.h&gt;</code></li> <li>If I include the videodev2 header in both the cpp files, it works <strong>only</strong> if I import it (videodev2) before the .h file.</li> <li>If I use <code>func(5, (uint32_t)5, (size_t)5, (abc*)0);</code> in the main.cpp file, I get the error that abc is not declared in this scope.</li> </ol> <p>I am compiling using the command: <code>g++ main.cpp head.cpp</code></p> <p>I am unable to figure out why is this. I would like to include the videodev2 header in the .h file since, it is almost certain that the code using the .h file will be dependent on it. But it seems that including it in .h file has no effect at all.</p> <p>I must be honest here. This was C code which I had to convert to C++. I know that I am not conforming to the best practices and standards. But why is this behaviour seen?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload