SDL_stdinc.h inlines problematic when application not compiled in exact same feature environment

not compiled in exact same feature environment
Message-ID:
<CAEyBR+VGFx1PC_EcGtVmABxk3DK+R5Y546ocZY3WgDteep+hkg at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Newer versions do implement some C99 features though. But even then,
many people are still stuck using VS2008, which in C mode implements a
bastardized version of C89 (which is also important to know, it isn’t
even C89 compliant!).

I wish people would just upgrade sigh

It could be worse. I remember reading that after Microsoft finally
released a replacement for Visual Studio 6, some people still HAD TO
stick with the old 90s version for legacy support reasons.> Date: Sat, 15 Jun 2013 08:17:17 -0300

From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application

So true – in the OS world, “some people” is a large group … 39% of
the SMBs and enterprises are still on XP as of 04/13 [1]. But for
development, I don’t see how folks are really “stuck” on 2008 since -
likely due to pressure from the wide availability of OSS toolchains -
the “Express” family of VisualStudio releases are made available for
free (/w registration) [2]. The VS documentation in SDL is slightly out
of date in that respect.

[1]


[2]
http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-productsOn 6/17/2013 12:29 AM, Jared Maddox wrote:

Date: Sat, 15 Jun 2013 08:17:17 -0300
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:
<CAEyBR+VGFx1PC_EcGtVmABxk3DK+R5Y546ocZY3WgDteep+hkg at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Newer versions do implement some C99 features though. But even then,
many people are still stuck using VS2008, which in C mode implements a
bastardized version of C89 (which is also important to know, it isn’t
even C89 compliant!).

I wish people would just upgrade sigh

It could be worse. I remember reading that after Microsoft finally
released a replacement for Visual Studio 6, some people still HAD TO
stick with the old 90s version for legacy support reasons.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Developers are stuck with VS2008 for the same reason enterprises are
stuck with XP - “it works so don’t change it”, especially since even
the most minimal change is bound to completely break the tool
pipeline. This is why it’s so horribly hard to update anything at all
:confused:

For the record, in many cases the blocker is either doing things in a
wrong way (and fixing it would take up even more maintenance) or some
other software that would need to be updated too to keep it working
but there’s a fee to do that and it’d be costly to do it.

2013/6/17, Andreas Schiffler :> So true – in the OS world, “some people” is a large group … 39% of

the SMBs and enterprises are still on XP as of 04/13 [1]. But for
development, I don’t see how folks are really “stuck” on 2008 since -
likely due to pressure from the wide availability of OSS toolchains -
the “Express” family of VisualStudio releases are made available for
free (/w registration) [2]. The VS documentation in SDL is slightly out
of date in that respect.

[1]
http://www.zdnet.com/microsoft-dangles-windows-8-office-2013-carrots-to-get-smbs-off-windows-xp-7000013685/
[2]
http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products

On 6/17/2013 12:29 AM, Jared Maddox wrote:

Date: Sat, 15 Jun 2013 08:17:17 -0300
From: Sik the hedgehog <@Sik_the_hedgehog>
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:
<CAEyBR+VGFx1PC_EcGtVmABxk3DK+R5Y546ocZY3WgDteep+hkg at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Newer versions do implement some C99 features though. But even then,
many people are still stuck using VS2008, which in C mode implements a
bastardized version of C89 (which is also important to know, it isn’t
even C89 compliant!).

I wish people would just upgrade sigh

It could be worse. I remember reading that after Microsoft finally
released a replacement for Visual Studio 6, some people still HAD TO
stick with the old 90s version for legacy support reasons.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

…and because 2008 was the last version of the IDE that did not thoroughly and utterly suck, UI-wise.? Newer versions are just downright painful to use.

Mason________________________________
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Sent: Monday, June 17, 2013 8:17 AM
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application not compiled in exact same feature environment

Developers are stuck with VS2008 for the same reason enterprises are
stuck with XP - “it works so don’t change it”, especially since even
the most minimal change is bound to completely break the tool
pipeline. This is why it’s so horribly hard to update anything at all
:confused:

Which of these are ISO C89? That’s a stronger condition because
SDL might target another platform one day.

They work, which is the strongest condition! :slight_smile:
All of them are C89 and C99, except wcslen which is C99.

Macros are a bad idea. What happens if another library tries
the same thing? What happens if another library defines it?

These functions/macros should not be part of SDL’s public API. They should be
used internally by SDL for portability. Exposing them is one of the problems.

If they’re a portability concern, then wouldn’t/shouldn’t SDL users want
them in some form?

Jonny D

Which of these are ISO C89? That’s a stronger condition because
SDL might target another platform one day.

They work, which is the strongest condition! :slight_smile:
All of them are C89 and C99, except wcslen which is C99.

Macros are a bad idea. What happens if another library tries
the same thing? What happens if another library defines it?

These functions/macros should not be part of SDL’s public API. They should be used internally by SDL for portability. Exposing them is one of the problems.

Agreed. The real problem is the types:

Uint32 vs uint32_t

SDL has a problem: it wants C89 and it wants exact sized integer types.
C89 doesn’t provide them. However most platforms do. The problem
is what to do on those that don’t (Windows or whatever).

SDL chooses to use its own types (without the SDL prefix).

But this just doesn’t work, because these types
do not interoperate with other library code because
we don’t know what they are.On 18/06/2013, at 1:54 AM, John wrote:


john skaller
@john_skaller
http://felix-lang.org

I guess it depends on whether users expect SDL to be a C89 portability library.
But even then, users would want to call strdup() and memset() directly.On 06/17/2013 12:10 PM, Jonathan Dearborn wrote:

If they’re a portability concern, then wouldn’t/shouldn’t SDL users want them in
some form?

Jonny D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

not compiled in exact same feature environment
Message-ID: <51BF24E2.5020602 at ferzkopp.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

So true – in the OS world, “some people” is a large group … 39% of
the SMBs and enterprises are still on XP as of 04/13 [1]. But for
development, I don’t see how folks are really “stuck” on 2008 since -
likely due to pressure from the wide availability of OSS toolchains -
the “Express” family of VisualStudio releases are made available for
free (/w registration) [2]. The VS documentation in SDL is slightly out
of date in that respect.

[1]
http://www.zdnet.com/microsoft-dangles-windows-8-office-2013-carrots-to-get-smbs-off-windows-xp-7000013685/
[2]
http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products

not compiled in exact same feature environment
Message-ID:
<CAEyBR+UXgOaJ_NSj=OGHkC9K=JgYtgAe==idtiVLDCwX-KaQ5w at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Developers are stuck with VS2008 for the same reason enterprises are
stuck with XP - “it works so don’t change it”, especially since even
the most minimal change is bound to completely break the tool
pipeline. This is why it’s so horribly hard to update anything at all
:confused:

For the record, in many cases the blocker is either doing things in a
wrong way (and fixing it would take up even more maintenance) or some
other software that would need to be updated too to keep it working
but there’s a fee to do that and it’d be costly to do it.

Another conceptual case: you have an platform-agnostic app written in
C++. You boss wants you to port it to SDL2 (so that you can run it on
Android & iOS with relatively minor changes to the code), AND wants
the Windows plugins from the old version to continue working with the
new version. Thus, you get stuck using 2008 (or older) because that’s
what your unwisely C++ based dll interface was originally compiled
with on Windows (note: I am assuming there’s been some ABI breakage,
since that sometimes happens).

Not all “development” will be for new applications.> Date: Mon, 17 Jun 2013 08:01:54 -0700

From: Andreas Schiffler
To: SDL Development List
Cc: Jared Maddox <@Jared_Maddox>
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
Date: Mon, 17 Jun 2013 12:17:01 -0300
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application

Date: Mon, 17 Jun 2013 08:34:08 -0700 (PDT)
From: Mason Wheeler
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:
<1371483248.89149.YahooMailNeo at web122504.mail.ne1.yahoo.com>
Content-Type: text/plain; charset=“iso-8859-1”

…and because 2008 was the last version of the IDE that did not thoroughly
and utterly suck, UI-wise.? Newer versions are just downright painful to
use.

Mason

I wasn’t aware of IT managers commonly considering usability aspects
of their choices, though maybe that’s just because I don’t work in the
industry.

not compiled in exact same feature environment
Message-ID: <51BF314F.7030405 at leafygreengames.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Macros are a bad idea. What happens if another library tries
the same thing? What happens if another library defines it?

These functions/macros should not be part of SDL’s public API. They should
be
used internally by SDL for portability. Exposing them is one of the
problems.

Will SDL programmers use these functions on platforms that don’t
natively provide them, or provide them under a different name? If so,
then exporting the functions under the SDL namespace makes sense.

From another perspective, what do we GAIN from removing the functions?
As far as I can see, the only thing we gain from removing the
functions themselves is a inconsequential decrease in library size.> Date: Mon, 17 Jun 2013 11:54:55 -0400
From: John
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application

Date: Mon, 17 Jun 2013 12:10:46 -0400
From: Jonathan Dearborn
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:
<CA+DSiHYRvz63Fuyjh=E2BYJLH7oAVf+kfC_Rh4TfDLhoyVJjWA at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”

If they’re a portability concern, then wouldn’t/shouldn’t SDL users want
them in some form?

Presumably, yes.

Date: Tue, 18 Jun 2013 02:19:17 +1000
From: john skaller
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:

Content-Type: text/plain; charset=us-ascii

On 18/06/2013, at 1:54 AM, John wrote:

Which of these are ISO C89? That’s a stronger condition because
SDL might target another platform one day.

They work, which is the strongest condition! :slight_smile:
All of them are C89 and C99, except wcslen which is C99.

Macros are a bad idea. What happens if another library tries
the same thing? What happens if another library defines it?

These functions/macros should not be part of SDL’s public API. They should
be used internally by SDL for portability. Exposing them is one of the
problems.

Agreed. The real problem is the types:

Uint32 vs uint32_t

SDL has a problem: it wants C89 and it wants exact sized integer types.
C89 doesn’t provide them. However most platforms do. The problem
is what to do on those that don’t (Windows or whatever).

SDL chooses to use its own types (without the SDL prefix).

I’ve suggested before adding properly namespaced types, and
transitioning SDL2 over to using those, eliminating the old types
after the transition has been complete for two or three sub-versions.

But this just doesn’t work, because these types
do not interoperate with other library code because
we don’t know what they are.

However, I’m not certain if proper namespacing would fully address
your point here, so could you be a little more specific?

From another perspective, what do we GAIN from removing the functions?
As far as I can see, the only thing we gain from removing the
functions themselves is a inconsequential decrease in library size.

No, what we gain is the ability to actually use the library in a context
other than that with which it was compiled.

For example you can compile with a C89 environment.
But you might want to use the library from C++11.

You cannot do that, if C89 doesn’t have function f,
then SDL provides f, but C++ has f, so you get
a linkage error.

The general rule for linkers is that only one object file
or library can provide any given function, and exactly
one must provide it if required.

Depending on configuration script macros does NOT work
in headers, only when building the library binaries.

In general “feature test” configuration is an extremely bad idea;
they’re very bad if they test compilation ability, and they’re
absurd if they require test code to actually run. They’re
necessary building libraries due to the lack of standardisation
in badly designed systems programmers insist on using.

But if you apply these config script based feature tests
in header files, you can only use those headers in the
exact context the config script ran. Whereas you expect
a library to work provided the ABI is respected.

[Platform or compiler macros are a different issue, they’re
not nice but they’re OK in headers in principle because
they’re standardised by compiler vendors]

But this just doesn’t work, because these types
do not interoperate with other library code because
we don’t know what they are.

However, I’m not certain if proper namespacing would fully address
your point here, so could you be a little more specific?

The problem is exemplified by this:

// WINDOWS
#define OTHER_uint32 int
#define Uint32 long // SDL

// write a 32 bit value to p
void OTHER_LIBRARY_function (OTHER_uint32 *p);

// provide a 32 bit value via a pointer
Uint32 *SDL_LIBRARY_function (void);

//TYPE ERROR (int*, long* not compatible)
OTHER_LIBRARY_function ( SDL_LIBRARY_function ());

// BREAK STRICT ALIASING RULES
OTHER_LIBRARY_function ( 
	(OTHER_uint32*) SDL_LIBRARY_function ());

There is in fact no simple solution because the client does not know what
type OTHER_unit32 or Uint32 actually is. Knowing that they’re 32 bits
unsigned integers isn’t enough. [In this example you might use
copyup/copydown to solve the problem but it doesn’t work in
general because for example you might invoke a callback
and not know it refers to a variable that should have been modified
but wasn’t because we haven’t copied back yet. Or threads
or volatiles might be involved]

If both libraries used uint32_t from stdint.h instead of their own
private types, there’s no problem: they’re using the same type.

But stdint.h doesn’t exist on Windows so what do we do?

There is ONLY one correct solution. If SDL insists on C89 then
the USER must provide uint32_t. By specification, SDL cannot
do so. The logic is watertight I’m afraid. There’s no choice
in the matter. SDL must use int32_t and it must require the
client programmer provide it, assuming it insists on C89.
Attempting to provide both leads to an illformed contract
(in the sense of programming by contract).

The only issue here is how to effect this in a convenient way.
One solution is:

#include "SDL2.h"

This header is the pure SDL library header and it REQUIRES the
client to provide int32_t etc.

#include "SDL.h"

This is a compatibility hack. It provides int32_t itself.
On Linux or whatever has stdint.h it reads:

#include <stdint.h>
#include "SDL2.h"

On Windows, it says:

#define uint32_t int
...
#include "SDL2.h"

Sam actually suggested another model:

#define _SDL_stdinc_h
#include "SDL.h"

Here the #define prevents SDL_stdinc.h being included in SDL.h
because that’s the guard used. Now I can write:

#include <stdint.h>
#define Uint32  uint32_t
#include "SDL.h"

for example. That is not as clean but it solves the type problem
by delegating it to the user, and it’s compatible with existing
code. I don’t like this because I WANT to break all the existing
code, because all of it is wrong. And I want the documented
interfaces to use uint32_t NOT Uint32.

There’s a related issue with #define main which is also a seriously
bad idea. SDL needs to cleanly separate

(a) A library 
(b) A restricted kind of development environment

I have no problem with hacks to support easy development
of toy games provided they’re separated from the library,
which has lot of other more serious uses (like commercial
games, GUI’s, or the text editor I’m writing at the moment).

The pure library part is particularly important for people
creating language bindings (such as myself). Of course
If you make an app using C99 … then YOU are also creating
a language binding (the binding of C89 to C89 is reasonably
simple one hopes :slight_smile:

In summary: portability hackery belongs in library implementations.
It must not be put in interfaces. Interfaces are designed to support
interoperability and this requires strict adherence to the programming
by contract model or all hell breaks loose. If hackery is needed the
client programmer is the only one that can provide it because
only the client can deal with issues arising from multiple library
interfaces. It has to be on the head of the app developer.On 18/06/2013, at 12:51 PM, Jared Maddox wrote:


john skaller
@john_skaller
http://felix-lang.org

2013/6/17, Jared Maddox :>> Date: Mon, 17 Jun 2013 08:34:08 -0700 (PDT)

From: Mason Wheeler
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
not compiled in exact same feature environment
Message-ID:
<1371483248.89149.YahooMailNeo at web122504.mail.ne1.yahoo.com>
Content-Type: text/plain; charset=“iso-8859-1”

…and because 2008 was the last version of the IDE that did not
thoroughly
and utterly suck, UI-wise.? Newer versions are just downright painful to
use.

Mason

I wasn’t aware of IT managers commonly considering usability aspects
of their choices, though maybe that’s just because I don’t work in the
industry.

Retraining takes up time, and thereby costs money (since that’s time
that still needs to be paid the same way as if the worker was doing
its job, not to mention paying anything needed to get training going
for starters).

This is a well thought out and impassioned post, and I agree in principle
with your points.

However, SDL has evolved to meet real needs in porting code, not
necessarily to be a paragon of idiom.

I’m certainly open to evolving SDL in that direction, and I would recommend
a full audit and API improvement for SDL 3.0 :slight_smile:

Cheers!On Mon, Jun 17, 2013 at 10:54 PM, john skaller < skaller at users.sourceforge.net> wrote:

On 18/06/2013, at 12:51 PM, Jared Maddox wrote:

From another perspective, what do we GAIN from removing the functions?
As far as I can see, the only thing we gain from removing the
functions themselves is a inconsequential decrease in library size.

No, what we gain is the ability to actually use the library in a context
other than that with which it was compiled.

For example you can compile with a C89 environment.
But you might want to use the library from C++11.

You cannot do that, if C89 doesn’t have function f,
then SDL provides f, but C++ has f, so you get
a linkage error.

The general rule for linkers is that only one object file
or library can provide any given function, and exactly
one must provide it if required.

Depending on configuration script macros does NOT work
in headers, only when building the library binaries.

In general “feature test” configuration is an extremely bad idea;
they’re very bad if they test compilation ability, and they’re
absurd if they require test code to actually run. They’re
necessary building libraries due to the lack of standardisation
in badly designed systems programmers insist on using.

But if you apply these config script based feature tests
in header files, you can only use those headers in the
exact context the config script ran. Whereas you expect
a library to work provided the ABI is respected.

[Platform or compiler macros are a different issue, they’re
not nice but they’re OK in headers in principle because
they’re standardised by compiler vendors]

But this just doesn’t work, because these types
do not interoperate with other library code because
we don’t know what they are.

However, I’m not certain if proper namespacing would fully address
your point here, so could you be a little more specific?

The problem is exemplified by this:

    // WINDOWS
    #define OTHER_uint32 int
    #define Uint32 long // SDL

    // write a 32 bit value to p
    void OTHER_LIBRARY_function (OTHER_uint32 *p);

    // provide a 32 bit value via a pointer
    Uint32 *SDL_LIBRARY_function (void);

    //TYPE ERROR (int*, long* not compatible)
    OTHER_LIBRARY_function ( SDL_LIBRARY_function ());

    // BREAK STRICT ALIASING RULES
    OTHER_LIBRARY_function (
            (OTHER_uint32*) SDL_LIBRARY_function ());

There is in fact no simple solution because the client does not know what
type OTHER_unit32 or Uint32 actually is. Knowing that they’re 32 bits
unsigned integers isn’t enough. [In this example you might use
copyup/copydown to solve the problem but it doesn’t work in
general because for example you might invoke a callback
and not know it refers to a variable that should have been modified
but wasn’t because we haven’t copied back yet. Or threads
or volatiles might be involved]

If both libraries used uint32_t from stdint.h instead of their own
private types, there’s no problem: they’re using the same type.

But stdint.h doesn’t exist on Windows so what do we do?

There is ONLY one correct solution. If SDL insists on C89 then
the USER must provide uint32_t. By specification, SDL cannot
do so. The logic is watertight I’m afraid. There’s no choice
in the matter. SDL must use int32_t and it must require the
client programmer provide it, assuming it insists on C89.
Attempting to provide both leads to an illformed contract
(in the sense of programming by contract).

The only issue here is how to effect this in a convenient way.
One solution is:

    #include "SDL2.h"

This header is the pure SDL library header and it REQUIRES the
client to provide int32_t etc.

    #include "SDL.h"

This is a compatibility hack. It provides int32_t itself.
On Linux or whatever has stdint.h it reads:

    #include <stdint.h>
    #include "SDL2.h"

On Windows, it says:

    #define uint32_t int
    ...
    #include "SDL2.h"

Sam actually suggested another model:

    #define _SDL_stdinc_h
    #include "SDL.h"

Here the #define prevents SDL_stdinc.h being included in SDL.h
because that’s the guard used. Now I can write:

    #include <stdint.h>
    #define Uint32  uint32_t
    #include "SDL.h"

for example. That is not as clean but it solves the type problem
by delegating it to the user, and it’s compatible with existing
code. I don’t like this because I WANT to break all the existing
code, because all of it is wrong. And I want the documented
interfaces to use uint32_t NOT Uint32.

There’s a related issue with #define main which is also a seriously
bad idea. SDL needs to cleanly separate

    (a) A library
    (b) A restricted kind of development environment

I have no problem with hacks to support easy development
of toy games provided they’re separated from the library,
which has lot of other more serious uses (like commercial
games, GUI’s, or the text editor I’m writing at the moment).

The pure library part is particularly important for people
creating language bindings (such as myself). Of course
If you make an app using C99 … then YOU are also creating
a language binding (the binding of C89 to C89 is reasonably
simple one hopes :slight_smile:

In summary: portability hackery belongs in library implementations.
It must not be put in interfaces. Interfaces are designed to support
interoperability and this requires strict adherence to the programming
by contract model or all hell breaks loose. If hackery is needed the
client programmer is the only one that can provide it because
only the client can deal with issues arising from multiple library
interfaces. It has to be on the head of the app developer.


john skaller
skaller at users.sourceforge.net
http://felix-lang.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is a well thought out and impassioned post, and I agree in principle with your points.

An American and a Frenchman are discussing new technology.

The American says “Well, it works in practice!”.

And the Frenchman says “Ah, but does it work in theory?”

However, SDL has evolved to meet real needs in porting code, not necessarily to be a paragon of idiom.

You’re meeting real needs, but you’re also denying others.
The real point here is that there’s no reason to compromise the code.

We have one dev trying to use C99 to build apps and running
into problems because SDL was built with C89 (the default
picked by the config).

I’m certainly open to evolving SDL in that direction, and I would recommend a full audit and API improvement for SDL 3.0 :slight_smile:

Last time I looked at SDL version 2 was in development.
That was what, 5 years ago?

I won’t be alive when SDL 3 comes out :)On 18/06/2013, at 5:24 PM, Sam Lantinga wrote:


john skaller
@john_skaller
http://felix-lang.org

It’d be an incremental improvement to SDL that makes it more practical,
maintainable, portable, modern, and generally less weird.On 06/17/2013 10:51 PM, Jared Maddox wrote:


From another perspective, what do we GAIN from removing the functions?
As far as I can see, the only thing we gain from removing the
functions themselves is a inconsequential decrease in library size.

This thread is similar to when we suggested that SDL use bool instead of
SDL_bool, but not quite as contentious! :)On 06/18/2013 04:26 AM, john skaller wrote:

On 18/06/2013, at 5:24 PM, Sam Lantinga wrote:

This is a well thought out and impassioned post, and I agree in principle with your points.

An American and a Frenchman are discussing new technology.

The American says “Well, it works in practice!”.

And the Frenchman says “Ah, but does it work in theory?”

However, SDL has evolved to meet real needs in porting code, not necessarily to be a paragon of idiom.

You’re meeting real needs, but you’re also denying others.
The real point here is that there’s no reason to compromise the code.

We have one dev trying to use C99 to build apps and running
into problems because SDL was built with C89 (the default
picked by the config).

I’m certainly open to evolving SDL in that direction, and I would recommend a full audit and API improvement for SDL 3.0 :slight_smile:

Last time I looked at SDL version 2 was in development.
That was what, 5 years ago?

I won’t be alive when SDL 3 comes out :slight_smile:


john skaller
skaller at users.sourceforge.net
http://felix-lang.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

not compiled in exact same feature environment
Message-ID:

Content-Type: text/plain; charset=us-ascii

From another perspective, what do we GAIN from removing the functions?
As far as I can see, the only thing we gain from removing the
functions themselves is a inconsequential decrease in library size.

No, what we gain is the ability to actually use the library in a context
other than that with which it was compiled.

For example you can compile with a C89 environment.
But you might want to use the library from C++11.

You cannot do that, if C89 doesn’t have function f,
then SDL provides f, but C++ has f, so you get
a linkage error.

The general rule for linkers is that only one object file
or library can provide any given function, and exactly
one must provide it if required.

I suspect that was mentioned earlier, and I forgot. My bad.

Depending on configuration script macros does NOT work
in headers, only when building the library binaries.

In general “feature test” configuration is an extremely bad idea;
they’re very bad if they test compilation ability, and they’re
absurd if they require test code to actually run. They’re
necessary building libraries due to the lack of standardisation
in badly designed systems programmers insist on using.

But if you apply these config script based feature tests
in header files, you can only use those headers in the
exact context the config script ran. Whereas you expect
a library to work provided the ABI is respected.

[Platform or compiler macros are a different issue, they’re
not nice but they’re OK in headers in principle because
they’re standardised by compiler vendors]

Properly dividing the macros into “library build time” and “app build
time” would hopefully fix that, but would require:
A) that the SDL functions are always available in the static/stub
libraries by their SDL names (I actually support this if they’re to be
kept), and
B) the macro redefinitions only happen when the headers are included
by user code, so never during library-build-time.

Regardless, I personally think that the SDL prefixed functions should
either always be present in the produced object files, or be dropped
completely.

If both libraries used uint32_t from stdint.h instead of their own
private types, there’s no problem: they’re using the same type.

But stdint.h doesn’t exist on Windows so what do we do?

There is ONLY one correct solution. If SDL insists on C89 then
the USER must provide uint32_t. By specification, SDL cannot
do so. The logic is watertight I’m afraid. There’s no choice
in the matter. SDL must use int32_t and it must require the
client programmer provide it, assuming it insists on C89.
Attempting to provide both leads to an illformed contract
(in the sense of programming by contract).

The only issue here is how to effect this in a convenient way.
One solution is:

#include “SDL2.h”

This header is the pure SDL library header and it REQUIRES the
client to provide int32_t etc.

#include “SDL.h”

This is a compatibility hack. It provides int32_t itself.
On Linux or whatever has stdint.h it reads:

#include <stdint.h>
#include “SDL2.h”

On Windows, it says:

#define uint32_t int

#include “SDL2.h”

Sam actually suggested another model:

#define _SDL_stdinc_h
#include “SDL.h”

I’d prefer something more like this:

/* SDL_stdint.h */
#ifdef USER_STDINT
#include USER_STDINT
#else
#if NIX
#include <stdint.h>
#elif WIN
#define uint32_t int
#endif
#endif

(Note: I understand that trick to work within the standard, but I’m not sure)

That way SDL itself can use standard-sized types, yet (hopefully) step
on as few toes as possible.

Here the #define prevents SDL_stdinc.h being included in SDL.h
because that’s the guard used. Now I can write:

#include <stdint.h>
#define Uint32 uint32_t
#include “SDL.h”

for example. That is not as clean but it solves the type problem
by delegating it to the user, and it’s compatible with existing
code. I don’t like this because I WANT to break all the existing
code, because all of it is wrong. And I want the documented
interfaces to use uint32_t NOT Uint32.

SDL_uint32 would work as well of course (as long as it’s PROPERLY
defined, even though it’s inconveniently large), but I myself think
Uint32 is a poor name, likely to conflict with other libraries.
Unfortunately, it very possibly too late to change it for this version
series. I think that transitioning will require at a minimum several
minor releases.> Date: Tue, 18 Jun 2013 15:54:50 +1000

From: john skaller
To: SDL Development List
Subject: Re: [SDL] SDL_stdinc.h inlines problematic when application
On 18/06/2013, at 12:51 PM, Jared Maddox wrote:

Quoth Sam Lantinga , on 2013-06-13 22:33:52 -0700:

SDL_stdinc.h is designed to provide all the C library functionality used by
SDL, for platforms that don’t have the standard C library, or where you
don’t want C library dependencies for some reason.

I made a change so you can define SDL_STDINC_NO_INLINES, and SDL_stdinc.h
won’t define inline versions of the C library functions it provides.
http://hg.libsdl.org/SDL/rev/728e5f22a82f

Excellent—having finally gotten the chance to try this out, it seems
to work fine for me. I haven’t examined it too extensively, but it
does more or less the same thing my manual workaround was doing, but
officially and without the need for a local fork, so that’s good.

Cheers!

Likewise!

—> Drake Wilson

SDL_stdinc.h is designed to provide all the C library functionality used
by SDL, for platforms that don’t have the standard C library, or where you
don’t want C library dependencies for some reason.

I made a change so you can define SDL_STDINC_NO_INLINES, and SDL_stdinc.h
won’t define inline versions of the C library functions it provides.
http://hg.libsdl.org/SDL/rev/728e5f22a82f

Maybe I’m interpreting this in a wrong way, but weren’t compiler macros
discouraged to be used in headers as they are harder to read, document and
maintain?
http://sdl.5483.n7.nabble.com/Proposal-Drop-support-for-software-rendering-in-1-3-tp1144p1175.html(although
maybe this thread was referring only to configuration switches).

Also if other language bindings (pascal/java/whatnot) want to use/not use
inlined functions how can they turn it on or off without modifying the
library header itself?

Thanks,
VittorioOn Fri, Jun 14, 2013 at 7:33 AM, Sam Lantinga wrote:

In case this thread is still of any interest, m$ announced that visual
studio 2013 will support c99.


(news is rather old but quite interesting after all).

Cheers,
VittorioOn Thu, Jun 20, 2013 at 9:15 AM, Vittorio Giovara < @Vittorio_Giovara> wrote:

On Fri, Jun 14, 2013 at 7:33 AM, Sam Lantinga wrote:

SDL_stdinc.h is designed to provide all the C library functionality used
by SDL, for platforms that don’t have the standard C library, or where you
don’t want C library dependencies for some reason.

I made a change so you can define SDL_STDINC_NO_INLINES, and SDL_stdinc.h
won’t define inline versions of the C library functions it provides.
http://hg.libsdl.org/SDL/rev/728e5f22a82f

Maybe I’m interpreting this in a wrong way, but weren’t compiler macros
discouraged to be used in headers as they are harder to read, document and
maintain?
http://sdl.5483.n7.nabble.com/Proposal-Drop-support-for-software-rendering-in-1-3-tp1144p1175.html(although maybe this thread was referring only to configuration switches).

Also if other language bindings (pascal/java/whatnot) want to use/not use
inlined functions how can they turn it on or off without modifying the
library header itself?

Thanks,
Vittorio