Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > header include compatibility question

Reply
Thread Tools

header include compatibility question

 
 
songbird
Guest
Posts: n/a
 
      01-27-2011
hello,

i'm fiddling with some code that contains the following:

# ifdef BSD41
# include <time.h>
# else
# include <sys/time.h>
# endif

i would like to retain compatibility but need to
have the first expression evaluate to true for my
current system (i.e. <time.h> is the one that works)

Linux Debian Gnu Squeeze using gcc (Debian 4.4.5- 4.4.5

in reading what documents i can scrounge up (including
the FAQ) i couldn't find a list of constants like the
BSD41 for Debian or Gnu, so i'm not sure what would be
a compatible way to do this. sorry if this is a newbie
question, but i'm wading through this the best i can...

and yes, sure i can take out the defines and use a
straight include of <time.h>, but would that break
BSD compiles for someone else?


thanks for your replies,
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      01-27-2011
On 2011-01-27, songbird <(E-Mail Removed)> wrote:
> i'm fiddling with some code that contains the following:


> # ifdef BSD41
> # include <time.h>
> # else
> # include <sys/time.h>
> # endif


Wow, that's old.

> i would like to retain compatibility but need to
> have the first expression evaluate to true for my
> current system (i.e. <time.h> is the one that works)


It'd be useful to know what it is that's been requested that this header
is used for.

In general, though...

What this tells you is that at some point, "BSD41" was defined on some systems
and not on others, and the "some systems" used <time.h> and the "others"
used <sys/time.h>. Usually, either that means that "BSD41" is a new thing
and the "others" are old, or vice versa. So the question is, which of these
is likely the correct default now? (Nowadays, a lot more code will work
with the same header on all likely systems.)

The simple answer is: Try something, and if it works you're probably fine.
In this case, <time.h> is a standard header which is now pretty well supported
and a lot of things that may have migrated around back in the day are now
consistently there.

You can get more specific if you happen to know that BSD 4.1 was released in
1981. The chances are, that if the BSD41 version aligns with current
practice, the other branch of the system was useful for stuff which predated
1981. My guess is you can just drop that branch entirely and you'll never
see it not be the right choice.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      01-27-2011
On Thu, 2011-01-27, Seebs wrote:
> On 2011-01-27, songbird <(E-Mail Removed)> wrote:
>> i'm fiddling with some code that contains the following:

>
>> # ifdef BSD41
>> # include <time.h>
>> # else
>> # include <sys/time.h>
>> # endif

>
> Wow, that's old.


I happened to re-read the classic 1992 paper "#ifdef Considered
Harmful" today, and one of its examples contained #ifdef BSD_42.
("Figure 8. A truly awful style".)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-27-2011
songbird <(E-Mail Removed)> writes:
> i'm fiddling with some code that contains the following:
>
> # ifdef BSD41
> # include <time.h>
> # else
> # include <sys/time.h>
> # endif
>
> i would like to retain compatibility but need to
> have the first expression evaluate to true for my
> current system (i.e. <time.h> is the one that works)
>
> Linux Debian Gnu Squeeze using gcc (Debian 4.4.5- 4.4.5
>
> in reading what documents i can scrounge up (including
> the FAQ) i couldn't find a list of constants like the
> BSD41 for Debian or Gnu, so i'm not sure what would be
> a compatible way to do this. sorry if this is a newbie
> question, but i'm wading through this the best i can...
>
> and yes, sure i can take out the defines and use a
> straight include of <time.h>, but would that break
> BSD compiles for someone else?


If your code is only using things that are defined *by the
language standard* for <time.h>, then I'd just remove the #ifdef
and unconditionally use <time.h>. (BSD 4.1 was released in 1981;
unless you have some specific reason to think your code might be
used on such an ancient system, I wouldn't worry about it.)

The <sys/time.h> header is defined by POSIX; if you're using anything
POSIX-specific, you should include it (and keep in mind that your
code won't be portable to non-POSIX systems). POSIX also defines
some additional declarations in <time.h>. Note that including
<sys/time.h> doesn't (necessarily?) give you <time.h> so if you're
using the time() function, for example, <sys/time.h> by itself
probably isn't sufficient.

If you're using POSIX-specific stuff, comp.unix.programmer
is probably a better place to ask about it.

What declarations from <time.h> and/or <sys/time.h> is your code
actually using?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
songbird
Guest
Posts: n/a
 
      01-28-2011
Keith Thompson wrote:
> songbird writes:


>> i'm fiddling with some code that contains the following:
>>
>> # ifdef BSD41
>> # include <time.h>
>> # else
>> # include <sys/time.h>
>> # endif
>>
>> i would like to retain compatibility but need to
>> have the first expression evaluate to true for my
>> current system (i.e. <time.h> is the one that works)
>>
>> Linux Debian Gnu Squeeze using gcc (Debian 4.4.5- 4.4.5
>>
>> in reading what documents i can scrounge up (including
>> the FAQ) i couldn't find a list of constants like the
>> BSD41 for Debian or Gnu, so i'm not sure what would be
>> a compatible way to do this. sorry if this is a newbie
>> question, but i'm wading through this the best i can...
>>
>> and yes, sure i can take out the defines and use a
>> straight include of <time.h>, but would that break
>> BSD compiles for someone else?

>
> If your code is only using things that are defined *by the
> language standard* for <time.h>, then I'd just remove the #ifdef
> and unconditionally use <time.h>. (BSD 4.1 was released in 1981;
> unless you have some specific reason to think your code might be
> used on such an ancient system, I wouldn't worry about it.)


ah, good thing.

out it goes for now. it's not that critical,
i'm just using this as a practice project
to get used to git and the other tools people
are developing with these days. i've not done
any coding beyond some simple projects for many
years. now that i have plenty of free time i
figured i'd refresh some skills and play with
some new toys.

the code compiles fine with <time.h> alone. it
has been worked on recently enough that it runs
with a few tweaks. [i won't say how many warnings
i'm ignoring and the commented out sections of
code that i'll ignore for now too... ]

the reason i picked this particular code is that
it is non-gui so i can upload/download versions
easy over a very slow connection and it happens to
be something i enjoyed messing with many many years
ago.

it does actually run so that is good, i have bugs
to fix yet.


> The <sys/time.h> header is defined by POSIX; if you're using anything
> POSIX-specific, you should include it (and keep in mind that your
> code won't be portable to non-POSIX systems). POSIX also defines
> some additional declarations in <time.h>. Note that including
><sys/time.h> doesn't (necessarily?) give you <time.h> so if you're
> using the time() function, for example, <sys/time.h> by itself
> probably isn't sufficient.
>
> If you're using POSIX-specific stuff, comp.unix.programmer
> is probably a better place to ask about it.


ok, i'll keep that in mind.


> What declarations from <time.h> and/or <sys/time.h> is your code
> actually using?


the time function, struct tm, and the type time_t,

for reference and fun i'm using K&R 2nd ed and
C Traps and Pitfalls. i'm still ****ed at the SOB
who stole my first K&R edition.


thanks again,
 
Reply With Quote
 
songbird
Guest
Posts: n/a
 
      01-28-2011
Seebs wrote:
> On 2011-01-27, songbird <(E-Mail Removed)> wrote:
>> i'm fiddling with some code that contains the following:

>
>> # ifdef BSD41
>> # include <time.h>
>> # else
>> # include <sys/time.h>
>> # endif

>
> Wow, that's old.


*laughs* yeah, the original code is from the mid-80s.
it's been tweaked and changed over the years, the last
person who worked on it messed with it in 2008, so i'm
just having to tweak it a little to get it to run.

ignoring the stuff he commented out that i'd like
to take a crack at fixing sometime and the compiler
warnings it compiles and runs with two header fixes
and one function replacement. not bad for two
years difference.

that it doesn't run fully is ok, i'm enjoying
the bug hunting as it is making me learn how to
use various tools i've not messed with before.
which is the whole point of this project anyways.


>> i would like to retain compatibility but need to
>> have the first expression evaluate to true for my
>> current system (i.e. <time.h> is the one that works)

>
> It'd be useful to know what it is that's been requested that this header
> is used for.
>
> In general, though...
>
> What this tells you is that at some point, "BSD41" was defined on some systems
> and not on others, and the "some systems" used <time.h> and the "others"
> used <sys/time.h>. Usually, either that means that "BSD41" is a new thing
> and the "others" are old, or vice versa. So the question is, which of these
> is likely the correct default now? (Nowadays, a lot more code will work
> with the same header on all likely systems.)
>
> The simple answer is: Try something, and if it works you're probably fine.
> In this case, <time.h> is a standard header which is now pretty well supported
> and a lot of things that may have migrated around back in the day are now
> consistently there.
>
> You can get more specific if you happen to know that BSD 4.1 was released in
> 1981. The chances are, that if the BSD41 version aligns with current
> practice, the other branch of the system was useful for stuff which predated
> 1981. My guess is you can just drop that branch entirely and you'll never
> see it not be the right choice.
>
> -s


righto. *whack!* thanks,


songbird
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Where to include header files / A question of style? Victor Bazarov C++ 18 02-21-2005 11:19 AM
#include headers that include this header Aguilar, James C++ 2 07-16-2004 05:56 PM
#include "bar" negates #include <string> ; how to fix? Danny Anderson C++ 5 08-15-2003 06:38 PM



Advertisments