DOS vs. Windows vs. Mac vs. Unix vs. NS

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Jim Vlc » Mon, 13 Sep 1993 16:05:31




> For example, the symbol SEEK_SET is supposed to be defined in 'stdio.h'
> (according to the POSIX standard, that is), but it's usually in
> 'unistd.h' instead-- but not always.

The C standard dictates that SEEK_SET, SEEK_CUR and SEEK_END (among others)  
must be #defined in stdio.h.  This is not a POSIX requirement.  The only  
POSIX constraints on stdio.h are that it must #define L_ctermid and  
STREAM_MAX and declare fdopen() and fileno() if _POSIX_SOURCE is #defined.  
It may optionally #define L_cuserid if _POSIX_SOURCE is #defined.

POSIX 1003.1 _does_ however, require that unistd.h #define SEEK_SET &c if  
_POSIX_SOURCE is #defined.  Thus, if you desire POSIX conformance, #include  
unistd.h.

Quote:> Sometimes, it's not defined at all.
> GNU, for example, puts it in 'unistd.h'.  The headers in SunOS 4.1.3 don't
> define it at all, and Centerline's products define it in 'stdio.h'.

Are you sure about the SunOS headers?  Here's a test I ran on my SPARC at  
work:

% fgrep SEEK_SET /usr/include/unistd.h
#ifndef SEEK_SET
#define SEEK_SET        0       /* Set file pointer to "offset" */
% uname -a
SunOS epimbe 4.1.1 1 sun4c

Perhaps they've moved unistd.h to /usr/5include since 4.1.1??

Quote:> As a result, the code ends up littered with an incomprehensible mess of
> #ifdef's and #defines, to hack around the peculiarities of each
> environment.

I do agree on this, and am rapidly tiring of system dependencies being  
handled by #ifdefs.

I've found the "POSIX Programmer's Guide" (Donald Lewine, O'Reilly, ISBN  
0-937175-73-0) to be priceless.  I strongly recommend this book to anyone  
using C, whether they be UNIX programmers or not (but particularly if they  
are).  It not only helps understand "what is defined where and by which  
standard", but also helps programmers to "Do the Right Thing" by clarifying  
what is POSIX conformant and what is historical baggage.

--
-----------------------------------------------------------------------------
Jim Vlcek                         UNIX for $166!
uunet!molly!vlcek                 Novell UnixWare from Information Foundation

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Guy Harr » Wed, 15 Sep 1993 08:03:14


Quote:>Perhaps they've moved unistd.h to /usr/5include since 4.1.1??

Nope:

        bootme$ egrep SEEK_SET /usr/include/unistd.h
        #ifndef SEEK_SET
        #define SEEK_SET        0       /* Set file pointer to "offset" */
        bootme$ uname -a
        SunOS bootme 4.1.3 6 sun4m

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by John Hende » Wed, 15 Sep 1993 15:05:15


Quote:uunet!molly!vlcek (Jim Vlcek) writes:
>I do agree on this, and am rapidly tiring of system dependencies being  
>handled by #ifdefs.

        Speeking of which, is there a filter program that will output C
code with all the undefined portions removed? This would sure make
reading through code written to run on a million systems easier to read.

--
John Henders       GO/MU/E d* -p+ c+++ l++ t- m--- s/++ g+ w+++ -x+

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Holger U » Wed, 15 Sep 1993 21:16:25



> uunet!molly!vlcek (Jim Vlcek) writes:
> >I do agree on this, and am rapidly tiring of system dependencies being  
> >handled by #ifdefs.
>    Speeking of which, is there a filter program that will output C
> code with all the undefined portions removed? This would sure make
> reading through code written to run on a million systems easier to read.

Try cc with the options -E or -P.

--
|   Holger Uhr   ***   Pohlweg 60   ***   33098 Paderborn   ***   Germany   |

|How to become immortal: Read this signature tomorrow and follow its advice.|

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by C.J. Niels » Thu, 16 Sep 1993 04:03:29



>uunet!molly!vlcek (Jim Vlcek) writes:

>>I do agree on this, and am rapidly tiring of system dependencies being  
>>handled by #ifdefs.

>    Speeking of which, is there a filter program that will output C
>code with all the undefined portions removed? This would sure make
>reading through code written to run on a million systems easier to read.

I don't know of a program, but then, you don't need one.  Run the code through
a C compiler, and specify that you only want the code preprocessed.  Most C
compilers have an option like this, including Microsoft's.

--- Chris

===============================================================================
Christopher J. Nielsen

Student                            |  Junior Software Engineer
Rochester Institute of Technology  |  Northern Telecom - Rochester, New York

[Opinions expressed here may not represent those of my organizations.]

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Dan P » Thu, 16 Sep 1993 06:24:59




>>uunet!molly!vlcek (Jim Vlcek) writes:

>>>I do agree on this, and am rapidly tiring of system dependencies being  
>>>handled by #ifdefs.

>>        Speeking of which, is there a filter program that will output C
>>code with all the undefined portions removed? This would sure make
>>reading through code written to run on a million systems easier to read.

>I don't know of a program, but then, you don't need one.  Run the code through
>a C compiler, and specify that you only want the code preprocessed.  Most C
>compilers have an option like this, including Microsoft's.

The code resulted after preprocessing is almost illegible, since _all_
the macros have been substituted. I wouldn't enjoy looking at something
like this, which is much worse than the original file, full of #ifdef's.

Dan
--
Dan Pop
Tel:   +41.22.767.2335

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Conrad Huang %C » Thu, 16 Sep 1993 05:21:05


Quote:>>        Speeking of which, is there a filter program that will output C
>>code with all the undefined portions removed? This would sure make
>>reading through code written to run on a million systems easier to read.

Yes.  There is a program called "unifdef" which does exactly what you
want.  It was contributed to the 4BSD, so it should be available at
various ftp sites (e.g., ftp.uu.net).

Quote:>I don't know of a program, but then, you don't need one.  Run the code through
>a C compiler, and specify that you only want the code preprocessed.  Most C
>compilers have an option like this, including Microsoft's.

If your goal is to *read* the program, having the C preprocessor replace
all symbolic constants with the actual values is *probably* not ideal.

Conrad

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by John Hende » Thu, 16 Sep 1993 10:07:19




>>        Speaking of which, is there a filter program that will output C
>>code with all the undefined portions removed? This would sure make
>>reading through code written to run on a million systems easier to read.
>I don't know of a program, but then, you don't need one.  Run the code through
>a C compiler, and specify that you only want the code preprocessed.  Most C
>compilers have an option like this, including Microsoft's.

    As someone pointed out to me in e-mail, however, this strips out
comments and defines, except for rare compilers, of which gcc is not
one.  I think, for me, the lack of these would make the source less
readable than the original clutter.

--
John Henders       GO/MU/E d* -p+ c+++ l++ t- m--- s/++ g+ w+++ -x+

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Derek Hardi » Thu, 16 Sep 1993 18:59:25



|>

|> >>
|> >>  Speaking of which, is there a filter program that will output C
|> >>code with all the undefined portions removed? This would sure make
|> >>reading through code written to run on a million systems easier to read.
|>
|> >I don't know of a program, but then, you don't need one.  Run the code through
|> >a C compiler, and specify that you only want the code preprocessed.  Most C
|> >compilers have an option like this, including Microsoft's.
|>
|>     As someone pointed out to me in e-mail, however, this strips out
|> comments and defines, except for rare compilers, of which gcc is not
|> one.  I think, for me, the lack of these would make the source less
|> readable than the original clutter.

Emacs has a hideifdef mode. This will hide any conditionally compiled bits that you wish to hide.

It works as follows. This code

#ifdef HIDDEN
if(a > b)
{
#endif
        a += b;
#ifdef HIDDEN

Quote:}

#endif

after hiding the block HIDDEN shows:

#ifdef HIDDEN ...
#endif
        a += b;
#ifdef HIDDEN ...
#endif

Derek
--
"When a man is tired of Ankh-Morpork, he is tired of ankle-deep slurry."
        -- (Terry Pratchett, Mort)

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Holger U » Thu, 16 Sep 1993 18:09:50





> >>   Speaking of which, is there a filter program that will output C
> >>code with all the undefined portions removed? This would sure make
> >>reading through code written to run on a million systems easier to read.
> >I don't know of a program, but then, you don't need one.  Run the code through
> >a C compiler, and specify that you only want the code preprocessed.  Most C
> >compilers have an option like this, including Microsoft's.
>     As someone pointed out to me in e-mail, however, this strips out
> comments and defines, except for rare compilers, of which gcc is not
> one.  I think, for me, the lack of these would make the source less
> readable than the original clutter.

The option -C used with the -E option tells the preprocessor not to discard
comments.

--
|   Holger Uhr   ***   Pohlweg 60   ***   33098 Paderborn   ***   Germany   |

|How to become immortal: Read this signature tomorrow and follow its advice.|

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Takis Mercour » Thu, 16 Sep 1993 22:10:37


Holger Uhr writes



(John Henders) writes:

> > >>      Speaking of which, is there a filter program that will output C
> > >>code with all the undefined portions removed? This would sure make
> > >>reading through code written to run on a million systems easier to  
read.

> > >I don't know of a program, but then, you don't need one.  Run the  
code through
> > >a C compiler, and specify that you only want the code preprocessed.  
Most C
> > >compilers have an option like this, including Microsoft's.

> >     As someone pointed out to me in e-mail, however, this strips out
> > comments and defines, except for rare compilers, of which gcc is not
> > one.  I think, for me, the lack of these would make the source less
> > readable than the original clutter.

> The option -C used with the -E option tells the preprocessor not to  
discard
> comments.

Here,s the command you have been looking for.
Most Unix systems with some BSD heritage contain a command called unifdef.
NeXT certainly has it, and SunOS has had through 4.1.x, not sure about
Solaris 2.x.

Here's the top of the man page:
==========
UNIFDEF(1)          UNIX Programmer's Manual           UNIFDEF(1)

NAME
     unifdef - remove ifdef'ed lines

SYNOPSIS
     unifdef [ -t -l -c -Dsym -Usym -idsym -iusym ] ...  [ file ]

DESCRIPTION
     Unifdef is useful for removing ifdef'ed lines from a file
     while otherwise leaving the file alone.  Unifdef is like a
     stripped-down C preprocessor: it is smart enough to deal
     with the nested ifdefs, comments, single and double quotes
     of C syntax so that it can do its job, but it doesn't do any
     including or interpretation of macros.  Neither does it
     strip out comments, though it recognizes and ignores them.
.....

Takis Mercouris

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by Robert Gas » Thu, 16 Sep 1993 23:26:47


:       Speeking of which, is there a filter program that will output C
: code with all the undefined portions removed? This would sure make
: reading through code written to run on a million systems easier to read.

Try using the -E flag when compiling the source ... It will run the
source though cpp, resulting in the code applicable to your system ...

--> robert

 
 
 

DOS vs. Windows vs. Mac vs. Unix vs. NS

Post by N Tomczak-Jaegerma » Fri, 17 Sep 1993 00:34:46




>>        Speeking of which, is there a filter program that will output C
>>code with all the undefined portions removed? This would sure make
>>reading through code written to run on a million systems easier to read.
>I don't know of a program, but then, you don't need one.  Run the code through
>a C compiler, and specify that you only want the code preprocessed.  Most C
>compilers have an option like this, including Microsoft's.

Running your code through preprocessor (if possible, some compilers
have this step integrated) does "wonders" to a code readability.
On the other hand it is possible to find somewhere on the net a source
to a small utility called 'ifdef' which should do a required cleanup.

   Michal Jaegermann

 
 
 

1. Linux vs OS2 vs NT vs Win95 vs Multics vs PDP11 vs BSD geeks

        Every machine and operating system has got its useful
purpose...

        I see no point in argueing with people which OS is better, and
which is worse, and what will survive and what wont...

        The bottom line is obviously the best OS is the one that make
the end user most productive.    Ive used quite a variety of software
from intel, ibm, MS, sun, GNU, DEC/compaq, etc,   and everything OS
has got its UPz and DOWnz, so depending on what you want to do with it
yer machine, probably determines what OS you run.

        So lets cut to the chase -  OS bashing is a waste of time,
and most of the time I'd say the person putting it down just hasn't
seen that particular OS's potential,  or should I say speciality....

      Hell,  Plan 9 has even got some interesting features.. <snicker>

       And all PC users know,  that no matter what use on a day to day
basis on the PC, that one day you will need to boot good ole ancient
DOS to do something...

2. Identify IDE device?

3. Perfomance: tar vs ftp vs rsync vs cp vs ?

4. xfree86 version

5. Slackware vs SuSE vs Debian vs Redhat vs ....

6. Broken HD detection slows down boot

7. KDE vs. Openlook vs. Xfree86 vs. MetroX vs. CDE

8. PPP,DIP,SLIP,MINICOM = OMIGOD

9. Redhat vs Debian vs Yggdrasil vs Caldera vs ...

10. Short Summary of Linux vs. Win9X vs. Mac vs. ???

11. Desktop vs Window Manager vs X11 vs OS

12. Linux Advocacy - Linux vs Windows 2000 vs Be vs OS/2

13. BSD vs S5 vs MACH vs OSF/1 (no religion, please!)