sscanf and int64 in Win32 and Unix - different results?

M

Michael Wojcik

I mean : how many of us are _really_ programming in C?

I don't know how many of you are, but quite a large number of us are.
I believe most
of us are actually programming in C++ (or at least using a C++
compiler).

Your belief is unfounded, for various reasonable values of "us".
C++ is based on C89, not on C99. I don't see C++ changing
its standard to conform to C99 and I don't see that many C99 compilers
for that matter.

It is possible that what you see does not precisely correspond with
reality.
I think the question "will it compile and run correctly on a
conforming C++ compiler?" is more important than "is it C99
compliant?".

You're welcome to think whatever you like. Most of us[1] who actually
write C do not care whether our C code is acceptable to a conforming
C++ compiler, any more than we care if it is acceptable to a Fortran
compiler or a LISP interpreter or a Jacquard loom.


1. There are some exceptions; the canonical one in c.l.c is
Dinkumware, who have good reason to write code which is both portable
C and portable C++. However, few of us are in the implementation
business.
 
C

Chris Croughton

*Raises hands*

Well, I'm not at the moment because I'm reading and replying to Usenet,
but my job is about programming in C.
I don't know about "most of us", but it's not true in my case, anyway.

I use C++ as well, but I know which one I'm using for particular things.
Some I write in C, for maximum portability (more systems have C
compilers installed than C++ compilers), some I write in C++ for use of
features in that language. When I get around to installing an Ada
compiler I'll use that for some things, but even though it will be
provided with the same command line interface (GCC) it still won't be a
C or C++ compiler.

Chris C
 
M

Mark McIntyre

I could think of a couple of reasons. A certain C++ compiler might be
a very attractive development platform (with neat components for the
GUI, etc.).

So might a .net compiler. Whats your point?
But let me put it another way then :

Would you make use of C99 constructs of which you know that they won't
compile on a C89/90 compiler? (like compound literals, designated
initializers, etc.).

If I had to use a C89 compiler, obviously not. But then if I was
compiling for a K&R C compiler, or a fortran compiler etc. I'm really
not sure what your point is.
Well, at least I _believed_ that most C programmers here actually make
use of a C++ compiler. You're far more certain of their behaviour :)

You seel to have b*gger all experience of using different C++
compilers. We've just ported a raft of stuff from VC6 to VC7, and from
gcc332 to gcc341. Both migrations were a pain in the a*ss, especially
as the result had to compile on both VC7 *and* gcc341.
 
M

Mark McIntyre

I think he has a point.

If his point is "at the moment, there are more people using
C89-compliant compilers than C99-compliant ones" then I'd agree.

If his point is "C99 doesn't exist," then clearly he's talking
bollocks.
I don't see C99 becoming as well supported as C89/90.

I'm sure people said that about C89 "it'll never catch on, this
newfangled prototype stuff".
I think it's a wiser choice to make sure that the C code will also
compile on a C++ compiler (for future portability).

What you're saying is "write C++ but make it compile on a C compiler".
Thats daft. If I'm writing C++ I use templates, new, iterators etc
etc. If you force your code to be C compatible, you throw away the
entire point of writing C++.
 
P

Paul Mesken

On Fri, 27 May 2005 02:01:37 +0200, in comp.lang.c , Paul Mesken


What you're saying is "write C++ but make it compile on a C compiler".
Thats daft. If I'm writing C++ I use templates, new, iterators etc
etc. If you force your code to be C compatible, you throw away the
entire point of writing C++.

Nonono, I say it's wise to make C code (not C++ code) conforming to
C89/90 that _also_ compiles on a conforming C++ compiler (which can do
C89/90 anyway).

Surely that musn't be too hard to grasp.

What I'm saying is that I believe that it is more probable that C code
needs to be ported to C++ than C99 (based on my belief that C++ will
be more popular than C99).

Obviously, you believe that C99 is a huge success and that there is no
need to be so prudent. But neither MS VC++.not nor Borland Builder
does C99.

I don't say that one shouldn't write C++ at all, only that if you
write C, it should be C89/90 because it's better supported, also by
C++ compilers.
 
K

Keith Thompson

Paul Mesken said:
Nonono, I say it's wise to make C code (not C++ code) conforming to
C89/90 that _also_ compiles on a conforming C++ compiler (which can do
C89/90 anyway).

Surely that musn't be too hard to grasp.

No, it's not hard to grasp. We just think you're wrong. (When I say
"we", I don't claim to speak for everyone in the group, but I believe
I represent the majority view of the experts.)

Except in rare circumstances, there is no need for C code to be
restricted to the common subset of C and C++.

If I did have a need to write in the common subset of C and C++, I
would regularly test my code with both C and C++ compilers, which
would be a considerable increase of effort compared to just
programming in C. I *think* I know how to avoid incompatibilities,
but mistakes are inevitable; I might invoke a macro with a character
constant as an argument and forget that the macro uses sizeof, for
example. If there's no real benefit to maintaining C++ compatibility,
I'm not going to bother.

[snip]
Obviously, you believe that C99 is a huge success and that there is no
need to be so prudent. But neither MS VC++.not nor Borland Builder
does C99.

I don't say that one shouldn't write C++ at all, only that if you
write C, it should be C89/90 because it's better supported, also by
C++ compilers.

I don't think anyone here has claimed that C99 is a "huge success".
We were refuting Paul Hsieh's manifestly untrue statement, with which
you agreed, that "C89 is the final standard for C". There is
*partial* support for C99 in many compilers, and full support in a
few, and there's nothing wrong with taking advantage of that support
as long as you're careful about it. (I suspect that when/if gcc
provides full C99 support, it's going to be a tremendous boost for the
new standard's popularity.)

It often makes sense to use C89/C90 because it's better supported by C
compilers. The fact that it's better supported by C++ compilers is
largely irrelevant.
 
M

Mark McIntyre

Nonono, I say it's wise to make C code (not C++ code) conforming to
C89/90 that _also_ compiles on a conforming C++ compiler (which can do
C89/90 anyway).

Well, a) no it can't, not unless its also a C compiler and b) no its
not especially wise. And bear in mind that for your code to compile
in a C++ compiler, it has to actually *be* C++ code.
Surely that musn't be too hard to grasp.

Its easy to grasp, just IMHO rubbish.
What I'm saying is that I believe that it is more probable that C code
needs to be ported to C++ than C99 (based on my belief that C++ will
be more popular than C99).

I find it hard to concieve of anyone wanting to port a large C project
to C++, without wanting / needing to extensively rewrite it anyway, so
this seems to be not only incorrect but a big waste of time. YMMV.
Obviously, you believe that C99 is a huge success and that there is no
need to be so prudent.

I've never said that.
But neither MS VC++.not nor Borland Builder does C99.

So what? There's plenty of good compilers that do enough of it.
 
C

CBFalconer

Paul said:
.... snip ...

Nonono, I say it's wise to make C code (not C++ code) conforming
to C89/90 that _also_ compiles on a conforming C++ compiler (which
can do C89/90 anyway).

Surely that musn't be too hard to grasp.

What I'm saying is that I believe that it is more probable that C
code needs to be ported to C++ than C99 (based on my belief that
C++ will be more popular than C99).

There is absolutely no need for that. C++ uses:

extern "C" { /* C stuff */ }

to determine how to link, keyed on the __cplusplus identifier. All
you have to do is write your headers appropriately and your C code,
while remaining C, is usuable in a C++ system. C compilers are
forbidden from defining __cplusplus.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
W

websnarf

Keith said:
No, it's not hard to grasp. We just think you're wrong. (When I say
"we", I don't claim to speak for everyone in the group, but I believe
I represent the majority view of the experts.)

Except in rare circumstances, there is no need for C code to be
restricted to the common subset of C and C++.

Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.
If I did have a need to write in the common subset of C and C++, I
would regularly test my code with both C and C++ compilers, which
would be a considerable increase of effort compared to just
programming in C.

There are such a thing as makefiles and unit tests. Maybe some of the
"experts" in this group can tell you about them.
[...] I *think* I know how to avoid incompatibilities,
but mistakes are inevitable; I might invoke a macro with a character
constant as an argument and forget that the macro uses sizeof, for
example. If there's no real benefit to maintaining C++ compatibility,
I'm not going to bother.

Yeah and if your code doesn't need more than 640K, I don't think you
should bother about that either.

Dude *NOBODY* serious does C99 ... its not just a case of a few high
profile vendors.
I don't think anyone here has claimed that C99 is a "huge success".
We were refuting Paul Hsieh's manifestly untrue statement, with which
you agreed, that "C89 is the final standard for C".

I am speaking from the point of view of a programmer. You can't
program to the C99 standard, so in what sense does it exist to
programmers?
[...] There is *partial* support for C99 in many compilers,

Yes, these occupy the exact same usefulness as an compiler extension.
But they are also have exactly the same problems as well -- i.e., they
are not portable.
[...] and full support in a few,

That do not enjoy serious support.
[...] and there's nothing wrong with taking advantage of that support
as long as you're careful about it.

You lose portability -- so yes indeed you have to be careful that you
don't ever try to move the other code to another compiler.
[...] (I suspect that when/if gcc provides full C99 support, it's going to
be a tremendous boost for the new standard's popularity.)

And exactly what justifies your holding out hope for this? gcc has
moved to version 3, then 4 without making any progress on C99 support.
They have documented an extremely serious issue (enabling support for
variable length arrays apparently would break many a lot of the FSF
applications) that is preventing them from implementing C99. But more
importantly, nobody cares.
It often makes sense to use C89/C90 because it's better supported by C
compilers. The fact that it's better supported by C++ compilers is
largely irrelevant.

As you know the C++ standard is much younger and immensely harder to
implement. And unlike C99, every vendor is converging towards total,
or near total support.
 
D

Dik T. Winter

> Keith Thompson wrote: ....
>
> Those rare circumstances include cases where C code is directly
> included in C++ projects. I.e., its actually extremely common.

I have an (I admit pretty old) C and Fortran project. The C code is
11981 lines for 328282 bytes of code. I should bother to make it
C++ compatible, while about one third of the code is just to avoid
bugs in particular compilers? You must be kidding.

If you write code, as you do, with the intention that it is also
included in C++ projects, you have a point. But all C code I ever
have written is not intended to be included in C++ projects, so
why should I bother?

Moreover, my first encounter with C++ was when it was still a moving
target. I had this program that should be implemented on both SGI
(for which it was written) and on Sun. It was *impossible* to get
a single source that would compile on both. And that has taken me
quite some time. Since then I try to avoid C++.
 
W

websnarf

Dik said:
I have an (I admit pretty old) C and Fortran project. The C code is
11981 lines for 328282 bytes of code. I should bother to make it
C++ compatible, while about one third of the code is just to avoid
bugs in particular compilers? You must be kidding.

I notice that a lot of people in this groups have either chronic and
severe literacy problems, or massive comprehension defficiencies (I'll
stop short of suggesting that its aggressive retardation). You of
course missed the part that you just quoted directly above your
paragraph here where I said:

"Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common."

Now, if you actually try to fire some neurons between your ears, you
might notice that this sentence does not imply or recommend that you
make your C + Fortran project C++ compatible.
If you write code, as you do, with the intention that it is also included in C++ projects,
you have a point.

Actually, I have a proclivity to write code for external consumption
outside of my own personal control. In an effort to enhance the value
of such code, I often try to make it as universal as possible. But of
course, this does not describe *all* the code I write.
[...] But all C code I ever
have written is not intended to be included in C++ projects, so
why should I bother?

I dunno, who said you should bother?
Moreover, my first encounter with C++ was when it was still a moving
target. I had this program that should be implemented on both SGI
(for which it was written) and on Sun. It was *impossible* to get
a single source that would compile on both. And that has taken me
quite some time. Since then I try to avoid C++.

Interesting that the history of C was quite similar in this respect, at
least as I clearly recall it.
 
K

Keith Thompson

I notice that a lot of people in this groups have either chronic and
severe literacy problems, or massive comprehension defficiencies (I'll
stop short of suggesting that its aggressive retardation).

If you can manage to discuss technical matters without stooping to
personal abuse, I'll be happy to join you, even (or especially) if I
don't agree with you. Until then -- well, I don't use a killfile, but
if I did you'd be in it. Bye.
 
P

Paul Mesken

Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.

Thank God! I was beginning to get the impression that I was the only
one doing such a thing :)

To give an example : right now I'm doing a little hobby project making
a strategy game. The game's logic (its core, the "engine") is written
in C (even freestanding, it doesn't need the C library). This
maximizes its portability and the files are separated from the rest.
This is a Good Thing because I intend the thing to be public domain.

The game's engine _is_ basically the game but it still has to
communicate with the players (either human or AI), save and load
files, allocate memory for the game's data, etc.

These things are programmed in C++ and make use of some extensions
offered by my C++ compiler (wrapped in classes, of course).
 
K

Keith Thompson

Paul Mesken said:
On 28 May 2005 18:32:23 -0700, (e-mail address removed) wrote: [...]
Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.

Thank God! I was beginning to get the impression that I was the only
one doing such a thing :)

To give an example : right now I'm doing a little hobby project making
a strategy game. The game's logic (its core, the "engine") is written
in C (even freestanding, it doesn't need the C library). This
maximizes its portability and the files are separated from the rest.
This is a Good Thing because I intend the thing to be public domain.

<OT>
Be sure you know what "public domain" means. It's not the same thing
as "open source" or "freeware".
The game's engine _is_ basically the game but it still has to
communicate with the players (either human or AI), save and load
files, allocate memory for the game's data, etc.

These things are programmed in C++ and make use of some extensions
offered by my C++ compiler (wrapped in classes, of course).

This sounds like a perfect job for C++'s extern "C" construct.

Your description seems to imply that you compile your entire program,
including the "engine", with a C++ compiler. If you never use a C
compiler, what's the benefit of restricting the "engine" code to the
C-compatible subset of C++? Why not just use C++?

On the other hand, if you compile the "engine" code with a C compiler
and use extern "C" to interface to it, what's the benefit of
restricting it to the C++-compatible subset of C? The only real
restrictions I can think of are that you need to avoid using C++
keywords and types, like long long, that don't exist in C++; these
restrictions apply only to external declarations.
 
P

Paul Mesken

Paul Mesken said:
On 28 May 2005 18:32:23 -0700, (e-mail address removed) wrote: [...]
Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.

Thank God! I was beginning to get the impression that I was the only
one doing such a thing :)

To give an example : right now I'm doing a little hobby project making
a strategy game. The game's logic (its core, the "engine") is written
in C (even freestanding, it doesn't need the C library). This
maximizes its portability and the files are separated from the rest.
This is a Good Thing because I intend the thing to be public domain.

<OT>
Be sure you know what "public domain" means. It's not the same thing
as "open source" or "freeware".
</OT>

Yeah, I'm gonna throw it in public (the source and a windoze program)
and everyone can change it, use it, etc. It will not be copyrighted.

The game (which is quite simple in itself but hard to play for AIs) is
meant as a simple testbed platform to test out AI ideas. The game has
"fog of war", limited resources, etc. all the stuff that is hard for
an AI because succesfull play involves dynamic information gathering,
planning and speculation. It's not that I expect to make any money
from it at all. It's just a hobby project.

The amazing (or not) part was that it was hardest to bring back the
game to its essentials and to balance the consequences of choices a
player can make (avoiding loopholes and a "perfect strategy" that
always works). The simplest games are the hardest to make :)
Your description seems to imply that you compile your entire program,
including the "engine", with a C++ compiler. If you never use a C
compiler, what's the benefit of restricting the "engine" code to the
C-compatible subset of C++? Why not just use C++?

C is more portable and generates, typically, less code than C++. C is
a favorite language for embedded systems and old machines with little
memory. I don't believe C++ is. Who knows? Someone might want to make
a version for some homebrewn computer or a lousy, old 8 bit system :)

It's hardly profitable for me to program the engine in C++ (apart from
that I constantly have to pass a pointer to the game object in C).
 
M

Mark McIntyre

Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.

Rubbish, IME. I've been in the business for 15 years, and have only
twice come across this. One was a case where somehing was too complex
to be rewritten. The other was plain laziness. And in any events if
you need to do this, use a library, not the source. There's no reason
to need to mix source.

But hten, I don't know why I'm answering you. You're a troll.
There are such a thing as makefiles and unit tests. Maybe some of the
"experts" in this group can tell you about them.

You've *clearly* never worked on a large project. Duplication of build
and testing time is *not* trivial, makefiles and unit test suites
notwithstanding. We have to build a system for three platforms and two
compiler suites, and a full rebuild and retest can take days thanks to
the solaris build alone taking over 24 hours.
Dude *NOBODY* serious does C99 ... its not just a case of a few high
profile vendors.
Dork.


I am speaking from the point of view of a programmer. You can't
program to the C99 standard,

You can. Your own manifestly limited experience is no guide.
 
K

Keith Thompson

Paul Mesken said:
Yeah, I'm gonna throw it in public (the source and a windoze program)
and everyone can change it, use it, etc. It will not be copyrighted.

Or sell it without giving you a dime. It's your call, of course.

[...]
C is more portable and generates, typically, less code than C++. C is
a favorite language for embedded systems and old machines with little
memory. I don't believe C++ is. Who knows? Someone might want to make
a version for some homebrewn computer or a lousy, old 8 bit system :)

It's hardly profitable for me to program the engine in C++ (apart from
that I constantly have to pass a pointer to the game object in C).

I notice that you didn't actually answer my question. Do you compile
the "engine" code with a C compiler or with a C++ compiler?

If you're using a C++ compiler then you're really programming in (a
subset of) C++. If your concern is smaller code, it makes probably
sense to use a subset of C++, but there's no particular reason that
subset has to be C-compatible. And if your system as a whole depends
on C++, there's little point in maintaining portability to systems
that don't have C++ compilers.

On the other hand, if you're using a C compiler, there's little point
in restricting yourself to the C++-compatible subset of C. Just stick
to the C90 standard and your code will be as portable as it needs to
be.
 
P

Paul Mesken

But hten, I don't know why I'm answering you. You're a troll.

Then let me enlighten you :
You've *clearly* never worked on a large project.

Your own manifestly limited experience is no guide.

Ah yes, it's the same old story. Now that you're wriggling in the iron
grip of reason you're performing a last ditch effort to save some face
by defying your betters.

Your feeble skills are no match for the Dark Side of the Code.

(if you're trolling, troll with style :)
 
P

Paul Mesken

I notice that you didn't actually answer my question. Do you compile
the "engine" code with a C compiler or with a C++ compiler?

Oops, sorry about that.

I use a C++ compiler (Borland Builder in this case).
If you're using a C++ compiler then you're really programming in (a
subset of) C++. If your concern is smaller code, it makes probably
sense to use a subset of C++, but there's no particular reason that
subset has to be C-compatible. And if your system as a whole depends
on C++, there's little point in maintaining portability to systems
that don't have C++ compilers.

The "engine" of the game processes user input (the functions that
actually fetch that input are not portable and outside of the engine),
updates the game object (if necessary) and sends messages to the
players (the actual sending of the messages is performed by functions
invoked by function pointers and those functions are also outside the
game engine).

There are, basically, only two functions that are invoked from outside
the engine : ProcessMessage() and InitializeGame(). The whole engine
acts like a black box (you put stuff in and stuff comes out of it),
it's message driven.

This will all be done in C (freestanding) for maximum portability.

But this is not enough to have a running game implementation. There
are other functions necessary to make a working implementation of the
game, besides this engine. This involves communication with the player
(pipes, TCP/IP, direct, etc.), file management (saving games,
recording moves, loading maps), memory allocation (for the game object
itself and some workbuffers), the GUI (a very simple one to begin
with), etc.

These things are not portable (heck! you can't even clear the screen
with conforming C or C++ ;-)

I'll first make a simple application out of all of this (to test the
gameplay itself) and then proceed to make a little game server (a kind
of daemon) which can handle a lot of games simultaneously and gets
user input over the network (so that different AIs on different
machines can fight each other).

But my working game implementation will be all windows. Someone else
might take the "engine" (which is the portable core of it all) and
make a Linux implementation.

The only part that needs to be highly portable is the "engine" and
therefor it is written in C (freestanding). It doesn't really matter
in what language the other parts are written. They're not portable and
the engine doesn't need them. The engine is like a black box, it
communicates by sending and receiving messages in a simple char array
and it gets a pointer to a game object from outside.

Now, the reason why these non-engine parts are written in C++ is not
so much because of the language itself but because of the compiler
that has some neat extensions that will ease development of the
non-engine parts.

These components, however, are wrapped in classes so I have to program
in C++ if I want to use these components (one of my all time favorites
is the TStringGrid, I use it for almost everything :)

The engine itself I could just as well develop on a C compiler. But I
think of it as easier to add some units (as Builder calls them) rather
than link object files or even libraries (especially in the case of
Builder, I don't even believe it can handle COFF :) and it makes
debugging easier since I need the whole game to conveniently test the
engine.
 
R

Richard Bos

Those rare circumstances include cases where C code is directly
included in C++ projects. I.e., its actually extremely common.

extern "C".

HTH; HAND.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top