Question about C
-
- Posts: 1
- Joined: Fri Dec 08, 2006 10:14 am
Question about C
googled for a while but haven't found anything
don't know what to search for...
so i hope you can help my...
here is an example of some of my files
----------------------------------
video.c //includes video.h
video.h //includes bla.h
bla.c //includes bla.c
bla.h
kernel.c /inludes video.h
----------------------------------
my kernel.c includes video.h
but i don't want kernel.c to see
methods defined in bla.h.
how can i archive this??
i'm not sure if c can handle this or
if it is a linking issue
would be happy to get some advice
thx
braindamage
don't know what to search for...
so i hope you can help my...
here is an example of some of my files
----------------------------------
video.c //includes video.h
video.h //includes bla.h
bla.c //includes bla.c
bla.h
kernel.c /inludes video.h
----------------------------------
my kernel.c includes video.h
but i don't want kernel.c to see
methods defined in bla.h.
how can i archive this??
i'm not sure if c can handle this or
if it is a linking issue
would be happy to get some advice
thx
braindamage
Why not just do:
Would that work?
Code: Select all
"video.c" - includes "video.h" and "bla.h" (because it uses some of its functions?)
"video.h"
"bla.c" - includes "bla.h"
"bla.h"
"kernel.c" - includes "video.h", but not "bla.h"
@ braindamage:
The way you pictured the includes, no, you cannot do this. Walling pointed out an alternative.
Note that "being visible" is somewhat fuzzy when used in relation with includes. If you #include a header, that usually means you include function declarations, some datatype definitions (structs and typedefs), and a couple of #defines.
But if, for example, you use the function strcpy() without including <string.h>, your program would still compile - depending on your compiler settings, a warning might be generated. C does not require function declarations.
If you have a function foo() in bla.c which you do not want to be visible outside of bla.c at all, use the "static" keyword.
And try to organize your headers in a way that they do not include other headers, unless strictly necessary. The problem you have right now is only one inconvenience from a wide range of headaches that can arise from careless includings...
The way you pictured the includes, no, you cannot do this. Walling pointed out an alternative.
Note that "being visible" is somewhat fuzzy when used in relation with includes. If you #include a header, that usually means you include function declarations, some datatype definitions (structs and typedefs), and a couple of #defines.
But if, for example, you use the function strcpy() without including <string.h>, your program would still compile - depending on your compiler settings, a warning might be generated. C does not require function declarations.
If you have a function foo() in bla.c which you do not want to be visible outside of bla.c at all, use the "static" keyword.
And try to organize your headers in a way that they do not include other headers, unless strictly necessary. The problem you have right now is only one inconvenience from a wide range of headaches that can arise from careless includings...
Every good solution is obvious once you've found it.
[quote]C does not require function declarations. [/quote[
I beg to differ!
they aren't required for MOST function related stuff but to get the pointer to the function it must be declared!
also it's good to include them in ide's because most of them will parse it for you and give you nifty code completion
I beg to differ!
they aren't required for MOST function related stuff but to get the pointer to the function it must be declared!
also it's good to include them in ide's because most of them will parse it for you and give you nifty code completion
lol, I hate warnings..since my project has reached the "over 100 warnings" point, I just ignore them..
and I think my code looks better with the warnings rather than have (unsigned int) and (void *) everywhere...
for instance...
I can't get rid of the warning made by that code.. like that it gives "use of cast expressions as lvalues depricated"
and if I remove all the (unsigned int) stuff then it says something like "makes a pointer from an integer" or something about arithmetic...
and I think my code looks better with the warnings rather than have (unsigned int) and (void *) everywhere...
for instance...
Code: Select all
unsigned char *ptr;void *core;
(unsigned int)ptr=(unsigned int)ptr-(unsigned int)core;
and if I remove all the (unsigned int) stuff then it says something like "makes a pointer from an integer" or something about arithmetic...
and their is why I hate warnings...most of the tim it warns about something that would make your code next to unreadable and also a lot of times it prevents it from being portableThe casts are a bit ugly, but a least it'll get rid of the warning. In any case, either one will break horribly on platforms where sizeof(void *) doesn't equal sizeof(int).
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Going to have to agree, I've seen your code hckr83..Combuster wrote:There are always methods to make code more readable whilst not getting warnings.
Learn to bow for -Werror (or the msvc variant) and at some point you will stop noticing its being issued.
Or is it just me that compile warnings are a sign of hackish code?
Warnings are avoidable..
Ignoring them is not a good idea...
-Werror is a nice flag
You could pick an ISO standard:
-ansi
-std=c89 (or -std=iso9899:1990)
-std=c99 (or -std=iso9899:1999)
Or with GNU extensions:
-std=gnu89 (for C89 with GNU extensions)
-std=gnu99 (for C99 with GNU extensions)
And then you could turn on the -pedantic (or -pedantic-errors) flag..
There are various helpful STDC predefined macro's listed here.
GCC supported standards
http://gcc.gnu.org/onlinedocs/gcc/Standards.html
Various additional links..
http://www.open-std.org/jtc1/sc22/wg14/www/standards
http://www.open-std.org/jtc1/sc22/wg14/ ... /n1124.pdf
http://anubis.dkuug.dk/JTC1/SC22/WG14/w ... 869.txt.gz
Last edited by Brynet-Inc on Sun Dec 10, 2006 5:00 pm, edited 1 time in total.
No, you aren't.Combuster wrote: Or is it just me that compile warnings are a sign of hackish code?
Hmmm.... how to put this politely?
There is no reason why code shouldn't be both readable and warnings-free. Ignoring them for reasons of "readability" (or worse yet, "portability") just means you won't catch the one warning that actually tells you about a problem that could cost you hours of debugging.
Ignoring warnings is barely acceptable for ad-hoc code. For a project, it's a very, very poor design decision. Someone else building your code won't know which warnings are OK to ignore and which are genuine problems...
Code: Select all
unsigned char *ptr;void *core;
(unsigned int)ptr=(unsigned int)ptr-(unsigned int)core;
And -Wall -Werror isn't even half of it, as -Wall is a misnomer. PDCLib compiles warnings-free using:
Code: Select all
CFLAGS := -Wall -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion -Wstrict-prototypes
Last edited by Solar on Mon Dec 11, 2006 3:21 am, edited 1 time in total.
Every good solution is obvious once you've found it.
Note that "-pedantic" does not refer to "pedantic error-checking" but rather "pedantic adherence to what the standard says". At some points the standard requires a diagnostic where "GNU style" doesn't, and vice versa.Brynet-Inc wrote:And then you could turn on the -pedantic (or -pedantic-errors) flag...
Every good solution is obvious once you've found it.