A question about the DDK compiler and preprocessing

Hi,

I am looking for some documentation about how the DDK (XP SP1) compiler
deals with preprocessor directives and can’t seem to find anything
substantial.

I have inherited some “generic” C code that has been to preprocessor hell
and back so that it can compile on any platform known to man (and then
some). It’s supposed to be an easy drop in set of source code for some
encryption algorithms, but so far I can’t get the compiler to cooperate.
There are all types of things like below where I get macro redefinitions.

I’m relatively new to the DDK compiler and I’ve never done anything this
complex with preprocessor commands. Any help would be appreciated. If I
can make all the conditional compilation work, that would be a dream.
Please don’t tell me I have to do “manual preprocessing” to get this to
work. That will be the nightmare.

Thanks,
Paul

// Sample follows…

#define BLOCK_SIZE 32 // in one header file

#if 1
#define ARRAYS
#endif


#if BLOCK_SIZE == 16 // in another place

#ifdef ARRAYS
#define locals(y,x) x[4], y[4]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff

… Bunch of other nested preprocessor directives…

#elif BLOCK_SIZE == 24

#ifdef ARRAYS
#define locals(y,x) x[6], y[6]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff


#else

#ifdef ARRAYS
#define locals(y,x) x[8], y[8]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff



#endif

The DDK compiler is (pretty much) the same as the Visual Studio .NET
compiler and implements all the standard preprocessor stuff (you can read
the manuals online at the MSDN site).

A brief scan of the sample you gave looks fine to me; what error are you
getting?

/simgr

-----Original Message-----
From: Paul Benware [mailto:xxxxx@koolspan.com]
Sent: Tuesday, October 14, 2003 10:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] A question about the DDK compiler and preprocessing

Hi,

I am looking for some documentation about how the DDK (XP SP1) compiler
deals with preprocessor directives and can’t seem to find anything
substantial.

I have inherited some “generic” C code that has been to preprocessor hell
and back so that it can compile on any platform known to man (and then
some). It’s supposed to be an easy drop in set of source code for some
encryption algorithms, but so far I can’t get the compiler to cooperate.
There are all types of things like below where I get macro redefinitions.

I’m relatively new to the DDK compiler and I’ve never done anything this
complex with preprocessor commands. Any help would be appreciated. If I
can make all the conditional compilation work, that would be a dream.
Please don’t tell me I have to do “manual preprocessing” to get this to
work. That will be the nightmare.

Thanks,
Paul

// Sample follows…

#define BLOCK_SIZE 32 // in one header file

#if 1
#define ARRAYS
#endif


#if BLOCK_SIZE == 16 // in another place

#ifdef ARRAYS
#define locals(y,x) x[4], y[4]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff

… Bunch of other nested preprocessor directives…

#elif BLOCK_SIZE == 24

#ifdef ARRAYS
#define locals(y,x) x[6], y[6]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff


#else

#ifdef ARRAYS
#define locals(y,x) x[8], y[8]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff



#endif


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Well, that’s what I thought too.

The errors I’m getting are “macro redefinition” errors. In the example
below for instance, I’ve defined the BLOCK_SIZE to 32, but the compiler is
flagging redefinition errors in the “#if BLOCKSIZE == 16” section.
Specifically, the second occurrence of “locals” is being flagged.
Commenting out the first definition makes it happy. But the compiler
shouldn’t even be looking at this code in the first place if BLOCK_SIZE is
32!

-Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Graham, Simon
Sent: Tuesday, October 14, 2003 12:50 PM
To: Windows System Software Devs Interest List

The DDK compiler is (pretty much) the same as the Visual Studio .NET
compiler and implements all the standard preprocessor stuff (you can read
the manuals online at the MSDN site).

A brief scan of the sample you gave looks fine to me; what error are you
getting?

/simgr

-----Original Message-----
From: Paul Benware [mailto:xxxxx@koolspan.com]
Sent: Tuesday, October 14, 2003 10:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] A question about the DDK compiler and preprocessing

Hi,

I am looking for some documentation about how the DDK (XP SP1) compiler
deals with preprocessor directives and can’t seem to find anything
substantial.

I have inherited some “generic” C code that has been to preprocessor hell
and back so that it can compile on any platform known to man (and then
some). It’s supposed to be an easy drop in set of source code for some
encryption algorithms, but so far I can’t get the compiler to cooperate.
There are all types of things like below where I get macro redefinitions.

I’m relatively new to the DDK compiler and I’ve never done anything this
complex with preprocessor commands. Any help would be appreciated. If I
can make all the conditional compilation work, that would be a dream.
Please don’t tell me I have to do “manual preprocessing” to get this to
work. That will be the nightmare.

Thanks,
Paul

// Sample follows…

#define BLOCK_SIZE 32 // in one header file

#if 1
#define ARRAYS
#endif


#if BLOCK_SIZE == 16 // in another place

#ifdef ARRAYS
#define locals(y,x) x[4], y[4]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff

… Bunch of other nested preprocessor directives…

#elif BLOCK_SIZE == 24

#ifdef ARRAYS
#define locals(y,x) x[6], y[6]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff


#else

#ifdef ARRAYS
#define locals(y,x) x[8], y[8]
#else
#define locals(y,x) x##0, x##1, … // a lot of other stuff



#endif


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@koolspan.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

“Paul Benware” wrote in message news:xxxxx@ntdev…
>
> The errors I’m getting are “macro redefinition” errors. In the example
> below for instance, I’ve defined the BLOCK_SIZE to 32, but the compiler is
> flagging redefinition errors in the “#if BLOCKSIZE == 16” section.
> Specifically, the second occurrence of “locals” is being flagged.
> Commenting out the first definition makes it happy. But the compiler
> shouldn’t even be looking at this code in the first place if BLOCK_SIZE is
> 32!
>
> // Sample follows…
>
>
> #define BLOCK_SIZE 32 // in one header file
>
> #if 1
> #define ARRAYS
> #endif
>
> …
> …
>
> #if BLOCK_SIZE == 16 // in another place
>
> #ifdef ARRAYS
> #define locals(y,x) x[4], y[4]
> #else
> #define locals(y,x) x##0, x##1, … // a lot of other stuff
>
> … Bunch of other nested preprocessor directives…
> …
>
> #elif BLOCK_SIZE == 24
>
> #ifdef ARRAYS
> #define locals(y,x) x[6], y[6]
> #else
> #define locals(y,x) x##0, x##1, … // a lot of other stuff

Please provide a clearer description of the problem, with a clear
statement of which lines are producing errors and exactly what the
errors are. Please also be precise about how and where the different
controlling macros get defined - how are you sure that the definition
of BLOCK_SIZE as 32 is active, for example?

As stated, this makes no sense. With the example you give, for the
‘second occurrence of “locals”’ to be flagged, the compiler would
have to misinterpret the definition of BLOCK_SIZE and simultaneously
regard ARRAYS as both defined and undefined.

Compiling to produce a file containing the results of the preprocessor
stage would probably help a lot. This is simple and straightforward use
of the pre-processor - it certainly shouldn’t have any difficulty.

> I am looking for some documentation about how the DDK (XP SP1) compiler

deals with preprocessor directives and can’t seem to find anything
substantial.

In ANSI C standard way.

complex with preprocessor commands. Any help would be appreciated. If I
can make all the conditional compilation work, that would be a dream.

Worked for me for years.

Note that if the code is a GPL one, it is dirty like hell, and not supported by
anybody. So, writing your own code based on this GPLed one can be a better
idea.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> below for instance, I’ve defined the BLOCK_SIZE to 32, but the compiler is

flagging redefinition errors in the “#if BLOCKSIZE == 16” section.

Looks like the original code has both “BLOCK_SIZE” and “BLOCKSIZE”. A wise
coding style for sure :slight_smile:

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> Note that if the code is a GPL one, it is dirty like hell,
> and not supported by anybody.

There’s no necessary relationship between the license a
piece of code is released under and its dirtiness or the
availability of support. Plenty of GPL code has good
support available. Plenty is pretty ugly and doesn’t
have much suport available. It depends on who has worked
on it and who is interested in offering support for it,
but has nothing to do with the license.

> So, writing your own code based on this GPLed one can be a
> better idea.

If he does that, it’s still GPL code - so still dirty like
hell and still not supported by anybody, if you’re right.

Ya know what, I hate one-size-fits-all crap. Why? Because most men’s pants
now are made somewhere over there where all they have is little people. But
I’m a big people. So when I go buy those one-size-fits-all pants made
somewhere over there by those little people they don’t fit. Why? Because
when little people some where over there measure the biggest little people
they have and say this then is a 4X, its a little people 4X some where over
there and not a big people 4X over here. In other words, my new pants don’t
fit.

One-size-fits-all source code works basically the same way. Wally sprinkles
his #if/#idefs, Dilbert sprinkles his #if/#ifndefs, the pointer haired boss
has The-Fist-Of-God add a few, Ratbert adds a few and Catbert the-evil-HR
director hires a dyslectic to re-spell half of them. In other words, my
source won’t compile.

Paul, one source documentation would be the help files in Visual Studio
.NET. The compilers are nearly the same.


Gary G. Little
Seagate Technologies, LLC

“Paul Benware” wrote in message news:xxxxx@ntdev…
>
> Hi,
>
> I am looking for some documentation about how the DDK (XP SP1) compiler
> deals with preprocessor directives and can’t seem to find anything
> substantial.
>
> I have inherited some “generic” C code that has been to preprocessor hell
> and back so that it can compile on any platform known to man (and then
> some). It’s supposed to be an easy drop in set of source code for some
> encryption algorithms, but so far I can’t get the compiler to cooperate.
> There are all types of things like below where I get macro redefinitions.
>
> I’m relatively new to the DDK compiler and I’ve never done anything this
> complex with preprocessor commands. Any help would be appreciated. If I
> can make all the conditional compilation work, that would be a dream.
> Please don’t tell me I have to do “manual preprocessing” to get this to
> work. That will be the nightmare.
>
> Thanks,
> Paul
>
> // Sample follows…
>
>
> #define BLOCK_SIZE 32 // in one header file
>
> #if 1
> #define ARRAYS
> #endif
>
> …
> …
>
> #if BLOCK_SIZE == 16 // in another place
>
> #ifdef ARRAYS
> #define locals(y,x) x[4], y[4]
> #else
> #define locals(y,x) x##0, x##1, … // a lot of other stuff
>
> … Bunch of other nested preprocessor directives…
> …
>
> #elif BLOCK_SIZE == 24
>
> #ifdef ARRAYS
> #define locals(y,x) x[6], y[6]
> #else
> #define locals(y,x) x##0, x##1, … // a lot of other stuff
>
> …
> …
>
> #else
>
> #ifdef ARRAYS
> #define locals(y,x) x[8], y[8]
> #else
> #define locals(y,x) x##0, x##1, … // a lot of other stuff
>
> …
> …
> #endif
>
>
>

When Max says something is dirty, I believe him since he has
“fit-the-demons” trying to get the piece of crap in question to work. There
may be no relation, but there is also no guarantee that what works today
under a GPL will work tomorrow.


Gary G. Little
Seagate Technologies, LLC

“J. J. Farrell” wrote in message news:xxxxx@ntdev…
>
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
> >
> > Note that if the code is a GPL one, it is dirty like hell,
> > and not supported by anybody.
>
> There’s no necessary relationship between the license a
> piece of code is released under and its dirtiness or the
> availability of support. Plenty of GPL code has good
> support available. Plenty is pretty ugly and doesn’t
> have much suport available. It depends on who has worked
> on it and who is interested in offering support for it,
> but has nothing to do with the license.
>
> > So, writing your own code based on this GPLed one can be a
> > better idea.
>
> If he does that, it’s still GPL code - so still dirty like
> hell and still not supported by anybody, if you’re right.
>
>
>

Please, let’s not start bashing people outside the US again.

“Gary G. Little” wrote:

Ya know what, I hate one-size-fits-all crap. Why? Because most men’s pants
now are made somewhere over there where all they have is little people.

If replying by e-mail, please remove “nospam.” from the address.

James Antognini
Windows DDK MVP

“Gary G. Little” wrote in message
news:xxxxx@ntdev…
>
> When Max says something is dirty, I believe him since he has
> “fit-the-demons” trying to get the piece of crap in question
> to work.

How do you know this? Max wasn’t the original poster, and
the OP made no mention of what license the code is under.
Max didn’t suggest that he knew or had worked on the code
in question.

> There may be no relation, but there is also no guarantee
> that what works today under a GPL will work tomorrow.

How is that different from any other release license?
Are you suggesting there’s some executable hidden in the
wording of the license that sneaks out and changes the
code when you’re not looking?

Badly written code is badly written. Well written code
is well written. How does the license under which the
code is made available affect this?

> > So, writing your own code based on this GPLed one can be a

> better idea.

If he does that, it’s still GPL code - so still dirty like

Rewrite using your own naming and indents and drop the GPL logo.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> Badly written code is badly written. Well written code

is well written. How does the license under which the
code is made available affect this?

This is one of those “practical facts of life”. For now, I have no
explanations.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> > > So, writing your own code based on this GPLed one can be a
> > > better idea.
> >
> > If he does that, it’s still GPL code - so still dirty like
>
> Rewrite using your own naming and indents and drop the GPL logo.

Sounds like copyright theft to me - a lot of people get
very upset about that!

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> > Badly written code is badly written. Well written code
> > is well written. How does the license under which the
> > code is made available affect this?
>
> This is one of those “practical facts of life”. For now, I have no
> explanations.

I’ve worked for many years on widely ported operating system
code, most of it proprietary. By far the worst examples of
ill-designed buggy un-maintainable pre-processor Hell that
I’ve seen have been in proprietary code - and some of the
best handling of these issues has been in GPL code. I’ve
also seen good examples in proprietary code and bad ones in
GPL code. The deciding factor is the number, competence,
and laziness of people who have worked on the code, and is
unrelated to the license it’s released under.

I suspect that the only examples of widely ported code that
many people have seen are under the GPL. If they saw some
of the horrors in proprietary code bases they might think
differently.

Umm, yes, it does. Please think long and hard about whether to use GPL
code in your project. There are many advantages and disadvantages of
using GPL code. HOWEVER, if you do decide to use it, you MUST abide by
the GPL – and by copyright laws in general. And you must also have
some simple integrity – theft is wrong, no matter if the code doesn’t
have a dollar figure attached to it.

The FSF has quite successfully prosecuted many cases of theft of GPL IP.
It may be “free”, in the Orwellian inverted universe that Stallman
inhabits, but it certainly isn’t free.

Maxim, why on earth would you suggest doing such a thing?

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J. J. Farrell
Sent: Monday, October 20, 2003 7:21 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: A question about the DDK compiler and preprocessing

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> > > So, writing your own code based on this GPLed one can be a better
> > > idea.
> >
> > If he does that, it’s still GPL code - so still dirty like
>
> Rewrite using your own naming and indents and drop the GPL logo.

Sounds like copyright theft to me - a lot of people get
very upset about that!


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@sublinear.org To
unsubscribe send a blank email to xxxxx@lists.osr.com

> > > If he does that, it’s still GPL code - so still dirty like

>
> Rewrite using your own naming and indents and drop the GPL logo.

Sounds like copyright theft to me - a lot of people get
very upset about that!

Good luck to GNU in enforcing any copyrights on their software.

Frankly speaking, I would expect the legislation bodies to just declare GPL’s
license null and void, thus making GPLed software equal to public domain one,
so everybody will be able to make money off the GPLed code. Stopping these
“dogs on haystacks” (do not earn themselves and do not allow others) can be
really a benefit.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> GPL code. The deciding factor is the number, competence,

and laziness of people who have worked on the code, and is
unrelated to the license it’s released under.

Will you argue the fact that the psychological mindset of business IT
professionals and the GPL code authors differs a lot? Business professionals
are more prone to think about future, or instance.

The worst coding style I ever saw is GNU “grep” and Linux’s SCSI stack. This
really deserves a monument.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> Maxim, why on earth would you suggest doing such a thing?

OK, Arlie, looks like I must respond to you, though there is some minor risk we
will have yet another flame war on GPL. :slight_smile:

I consider GPL license as a virus which does lots of harm to commercial
software development.
I consider Stallman’s intent in inventing such stuff as a count-down bomb under
the software development business. There are already some companies went out of
business due to unfair competition with GPLed stuff.
I also consider picking up the stuff laying on the street and making money off
it - an absolutely normal and honest deed.
I also consider nobody does any harm to GPL people by starting the commercial
software off it.
What is their interest in prohibiting commercial software based on their code?
I can see no honest and decent interests there, except the aggressive and
destructive ones - “we will do the product for free to bring down your
business, and you will not even be able of defending yourself by using the law
on unfair competition”.

I’m the defender of the “positive law” idea. The legislation must be more based
on “being useful” and “balance of interests” principles, not on some sacred
cows.

With the “positive law” principle, GPL copyright defenders would be rejected at
court, since they will have no interest in this, not interest recognizeable by
the positive law.

Otherwise, the GPL people will continue to undermine the software development,
which will cause suffering to rather many people, on this very forum included.

If GPL people want to do something good for free due to moral obligations -
then issue the public domain software. Why introduce problems for others,
having no revenue off it? This is called “predatory business practice”
(according to Judge Jackson’s ruling on Microsoft’s case). A kind of unfair
competition.

Public domain software is like “res publicae”, it cannot be the subject of any
property-related rights. It is beyound the business at all - like trees,
forests, rivers and so on. Like the fine arts classics, if 50 years passed
after the death of the author. The good side of PD stuff is that it, being not
a business entity, does not undermine any business branch. It is not a
competitor, it is just for everybody’s pleasure, use (money-making included)
and benefit.

Nevertheless, we have GPL and the whole “movement” of aggressive nihilists.
Note that they do not want to issue the software for public domain! they insist
on GPL. From this I can only conclude that their real purpose is to undermine
the software development business due to their irrational “hatred to large
corporations” (which they are proud of - note, they are proud of hatred!), and
all their beautiful wording on improving the society and such - is just a
rationalization of this aggression.

Worse so. GPL software is mainly system-level. Everybody knows how tight is the
market of the system-level software. The “teenage smarties” (and the
50-years-old people who are still teenage smarties psychologically) of GPL have
the intellect necessary to do this job. Nevertheless, they cannot make money
off it. They did not prove that they really cost any money. So what? They give
away products for free, thus devaluing the work of their senior colleagues who
live off their jobs. Undermining the more successful people - instead of trying
to be one of them. Pathetic.

People here on this forum will suffer from GPL stuff first. People writing
Visual Basic+SQL apps - will not. GPL is to blame in undermining the market for
elite software developers, thus making this business - the business requiring
great intellectual powers - duller, lesser profitable and lesser respectful
(due to accent moved to simpler and duller kinds of development, which are also
lesser paid due to being lesser “requiring” and more open for wide masses).
This is devaluation of intellect after all.

It’s very bad that the modern Western and near-Western society has legally
defined mechanisms which protect such things.

One last moment of GPL. According to what I know, if the American uni is
governementally funded - then the law declares any results of the uni’s work to
be public domain, and not the uni’s IP (as it was with FreeBSD, AFAIK). The
thing is that the taxpayers have already paid for this work. If you want to
have IP on a product - then maintain your employees financially from your own
pocket, all is simple.

Also according to what I know, anything done by the employee in the working
time and/or using the employer’s equipment, is the property of the employer. If
you want to do something belonging to you - then work in spare time on your own
equipment, all is simple. Do your own investments.

Now - am I wrong that Stallman, while working on GCC, was a MIT’s employee? Or
maybe he wrote the whole compiler in his spare time? or MIT is not
governementally funded?

Am I wrong that Linux’s IP stack was written by Alan Cox in the University of
Wales? Was Alan an employee here? was the IP stack his assigned task as an
employee? was it done as a free research work permitted and sponsored by the
uni bosses? is the University of Wales - the governementally funded
institution? or maybe British laws differ from American this greatly?

Same question on ext2, IIRC written in the Pascal’s University in Paris.

The key idea of my reasoning is the attempt to analyze - who pays money to GPL
people? Usually the scientific insititutions. Then why the IP rights on the
software must belong to some FSF fund, and not to the employers of its authors
or to taxpayers? The role of science is to help commerce and business, not
undermine it.

Funny picture. The system-level developers pay taxes to the governement, which
are spent by the governement to fund the unis, and the uni’s employees (funded
off the developer’s taxes) write the software which undermines the development
business.

Allowing the commercial reuse of GPLed code will result in better shape of IT
business, more taxes to the governement, more money to maintain the same unis
and to hire more people there to do more GPLed stuff!

The root case here is IMHO trying to apply scientific notions to business
world. In science, everything is open. Note - even open for money-making. In
business world, things are closed to the money-making of others (patents etc),
but they are not for free anyway, and fed their makers. Not like science, which
cannot feed and requires the third-party feeder.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Maxim S. Shatskih wrote:

>>>If he does that, it’s still GPL code - so still dirty like
>>
>>Rewrite using your own naming and indents and drop the GPL logo.
>
>Sounds like copyright theft to me - a lot of people get
>very upset about that!

Good luck to GNU in enforcing any copyrights on their software.

Frankly speaking, I would expect the legislation bodies to just declare GPL’s
license null and void, thus making GPLed software equal to public domain one,
so everybody will be able to make money off the GPLed code.

Everybody *can* make money on GPLed code. You’re confusing free (libre)
with Free (unencumbered). Sell it, sell support for it, sell projects
built around it. Just don’t hoard your improvements. Give them back to
the community that provided the code to you. And if that’s not
acceptable, then simply don’t use GPLed code. Do a clean-room
reimplementation and keep it to yourself.