473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

C99 IDE for windows

I'm looking for a freeware c99 compiler for windows. I had intended to use
MS's Visual C++ Express and use its C capability. In the past with my MS
products, I've simply needed to make .c the filetype to invoke the C
compiler. Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a compiler,
but then setup.exe wants to download 87 megs of dot net framework hoggs
that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to get the
shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?
--
Women have simple tastes. They get pleasure out of the conversation of
children in arms and men in love.
H. L. Mencken
Jul 19 '08 #1
173 13739
On Jul 18, 5:49*pm, Ron Ford <r...@nowhere.netwrote:
I'm looking for a freeware c99 compiler for windows. *I had intended touse
MS's Visual C++ Express and use its C capability. *In the past with my MS
products, I've simply needed to make .c the filetype to invoke the C
compiler. *Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a compiler,
but then setup.exe wants to download 87 megs of dot net framework hoggs
that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to get the
shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?
http://www.thefreecountry.com/compilers/cpp.shtml
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
http://www.freeprogrammingresources.com/cppcomp.html
http://www.freebyte.com/programming/cpp/
Jul 19 '08 #2
On Fri, 18 Jul 2008 17:57:22 -0700 (PDT), user923005 posted:
On Jul 18, 5:49*pm, Ron Ford <r...@nowhere.netwrote:
>Anyone have another suggestion?

http://www.thefreecountry.com/compilers/cpp.shtml
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
http://www.freeprogrammingresources.com/cppcomp.html
http://www.freebyte.com/programming/cpp/
Thanks Dann, there seems to be many to choose from. I gave Cmega a try,
http://www.micro-ide.com/custom1.html ,but I don't think it's right for me,
until I know more about embedded systems. Their hello world program
compiles but does not build:

http://i33.tinypic.com/mra7ic.jpg

I'll give it another a try when I get more time.
--
Honor is simply the morality of superior men.
H. L. Mencken
Jul 19 '08 #3
Ron Ford wrote:
I'm looking for a freeware c99 compiler for windows. I had intended to use
MS's Visual C++ Express and use its C capability. In the past with my MS
products, I've simply needed to make .c the filetype to invoke the C
compiler. Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a compiler,
but then setup.exe wants to download 87 megs of dot net framework hoggs
that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to get the
shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?
Yes, use my compiler system lcc-win

The URL is below in my .sig.

Download 6MB.

o IDE
o C compiler (almost all C99)
o Extras like operator overloading and generic functions
o 105 digits precision floating point.
o bignums
o 128 bit integers
o Libraries: zip, perl regexp, matrix operations, and many others

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 19 '08 #4
Ron Ford wrote:
I'm looking for a freeware c99 compiler for windows. I had intended
to use MS's Visual C++ Express and use its C capability. In the past
It is not (and doesn't claim to be) a C99 compiler. It does (claim to)
comply to C89, as far as I know.
with my MS products, I've simply needed to make .c the filetype to
invoke the C compiler. Here's a link
some additional switches are needed to make it standard compliant.
http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a
compiler, but then setup.exe wants to download 87 megs of dot net
framework hoggs that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to get
the shell to stay open so I can see some output.

The development environment for gcc is austere.
gcc is not C99 compliant either.
Anyone have another suggestion?
Bye, Jojo
Jul 19 '08 #5
jacob navia wrote:
Ron Ford wrote:
>I'm looking for a freeware c99 compiler for windows. I had
intended to use MS's Visual C++ Express and use its C capability.
In the past with my MS products, I've simply needed to make .c
the filetype to invoke the C compiler. Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a
compiler, but then setup.exe wants to download 87 megs of dot net
framework hoggs that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to
get the shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?

Yes, use my compiler system lcc-win

The URL is below in my .sig.

Download 6MB.
If you (Ron Ford) do that be VERY cautious about portability. It
appears that lcc-win does not detect various forbidden constructs
under C99, besides omitting several required things. It will
probably improve, but the author tends to resist suggestions. I
believe it also lacks version numbers, making it hard to keep track
of revisions.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 19 '08 #6
Ron Ford wrote, On 19/07/08 02:38:
On Fri, 18 Jul 2008 17:57:22 -0700 (PDT), user923005 posted:
>On Jul 18, 5:49 pm, Ron Ford <r...@nowhere.netwrote:
>>Anyone have another suggestion?
http://www.thefreecountry.com/compilers/cpp.shtml
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
http://www.freeprogrammingresources.com/cppcomp.html
http://www.freebyte.com/programming/cpp/

Thanks Dann, there seems to be many to choose from.
You should be aware that most compilers do not fully support C99. Some
important ones (e.g. MSVC) only support C90 and have made no noticable
progress towards C99. You might find the following useful:
http://clc-wiki.net/wiki/C_resources
I gave Cmega a try,
http://www.micro-ide.com/custom1.html ,but I don't think it's right for me,
until I know more about embedded systems. Their hello world program
compiles but does not build:

http://i33.tinypic.com/mra7ic.jpg

I'll give it another a try when I get more time.
For problems with a specific set of tools you will have to ask in
whatever groups/mailing-list/forums support it.
--
Flash Gordon
Jul 19 '08 #7
On Sat, 19 Jul 2008 14:19:12 +0100, Flash Gordon posted:
Ron Ford wrote, On 19/07/08 02:38:
>On Fri, 18 Jul 2008 17:57:22 -0700 (PDT), user923005 posted:
>>On Jul 18, 5:49 pm, Ron Ford <r...@nowhere.netwrote:
>>>Anyone have another suggestion?
http://www.thefreecountry.com/compilers/cpp.shtml
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
http://www.freeprogrammingresources.com/cppcomp.html
http://www.freebyte.com/programming/cpp/

Thanks Dann, there seems to be many to choose from.

You should be aware that most compilers do not fully support C99. Some
important ones (e.g. MSVC) only support C90 and have made no noticable
progress towards C99. You might find the following useful:
http://clc-wiki.net/wiki/C_resources
I thought I read Jack Klein claiming that MS something Express was viable
as a C99 option. Oh well. I tried to fill the gap by installing Sun
Studio 12, but that doesn't work on OpenSolaris.:-(

The above link is helpful. From Dann's link yesterday, I found Visual
MingW, which is an IDE for windows. I think that information might be
newer than the information on C's wiki page.

For problems with a specific set of tools you will have to ask in
whatever groups/mailing-list/forums support it.
Thanks for saying that. It made me join their mailing list. I find
mailing lists to be hugely helpful for things like linmodems. One thing I
didn't get was the ability to debug from a pulldown menu. This screenshot
shows the attempt:

http://i34.tinypic.com/2q9x6jd.jpg

Also, the help menu is completely unpopulated, probably indicating that it
is a new project. If I can't get a debugging capability from this suite, I
will still be in the market for a new IDE.
--
Puritanism. The haunting fear that someone, somewhere, may be happy.
H. L. Mencken
Jul 20 '08 #8
In article <fr*****************************@40tude.net>
Ron Ford <wa********@netzero.netwrote:
>I wonder how closely the situation for compliance with F2003 compares to
C99. There seems to be one issue that has everyone stumped: parameterized
derived types. Of course, C won't have PDT's, but is there a single issue
that seems to have implementors pulling their hair out?
It seems to me that the answer to this question is "no". Different
"C99--" implementations (if I may call them that) are have different
parts that are "missing" or "broken" and there seems to be little if
any commonality.

GCC's set of missing/broken items is getting smaller, and for a
long time, the worst of them were due to C99 making slightly
*different* requirements from those for GNUC. (GNUC is the language
that GCC implemented; it was a lot like C99, only different. For
instance, the rules for VLAs and flexible array members were
different from those in C99.) That meant that changing the compiler
to do things the "C99 way" would break any code that depended on
GCC doing things the "GNUC way".

Other compilers had not implemented anything resembling those parts
of C99, and thus did not have "self-backwards-compatibility" problems
in the way.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jul 20 '08 #9
Ron Ford <ro*@nowhere.netwrites:
On Sat, 19 Jul 2008 09:45:44 +0200, Joachim Schmitz posted:
>Ron Ford wrote:
>>The development environment for gcc is austere.

gcc is not C99 compliant either.

How close is it?
Closer than even their own status pages suggests:

http://gcc.gnu.org/gcc-4.3/c99status.html

That reports wide character support as "missing" but as far as I can
tell, the only thing missing is format checking for the w* family
(i.e. you don't get a compile-time warning for wprintf(L"%d"); but you
do for printf("%d);).

VLAs are reported as broken, but I can't find an example of how. All
the obscure cases I have tried work -- no doubt I am not being devious
enough. Can anyone else find one?

--
Ben.
Jul 20 '08 #10
Ben Bacarisse wrote:
) VLAs are reported as broken, but I can't find an example of how. All
) the obscure cases I have tried work -- no doubt I am not being devious
) enough. Can anyone else find one?

Make a loop where you define a VLA at the beginning, of differing size.
Also, in the same loop, alloca() some memory, (and store the pointer in
an array.)

Of course, mixing VLA's and alloca() calls is nasty.
Is alloca() even part of C99 ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Jul 20 '08 #11
Ron Ford wrote, On 20/07/08 04:10:
On Sat, 19 Jul 2008 14:19:12 +0100, Flash Gordon posted:
<snip>
>You should be aware that most compilers do not fully support C99. Some
important ones (e.g. MSVC) only support C90 and have made no noticable
progress towards C99. You might find the following useful:
http://clc-wiki.net/wiki/C_resources

I thought I read Jack Klein claiming that MS something Express was viable
as a C99 option.
It has a C89 (the old standard) option but not, as far as I am aware, a
C99 option.
Oh well. I tried to fill the gap by installing Sun
Studio 12, but that doesn't work on OpenSolaris.:-(

The above link is helpful. From Dann's link yesterday, I found Visual
MingW, which is an IDE for windows. I think that information might be
newer than the information on C's wiki page.
<snip>

Please create an account and update anything that needs updating. It's a
Wiki and will only be as accurate and up to date as the last edit.
--
Flash Gordon
Providing the hosting for the CLC Wiki.
Jul 20 '08 #12
Willem wrote:
>
Of course, mixing VLA's and alloca() calls is nasty.
Is alloca() even part of C99 ?
No.

--
Ian Collins.
Jul 20 '08 #13
Willem <wi****@stack.nlwrites:
Ben Bacarisse wrote:
) VLAs are reported as broken, but I can't find an example of how. All
) the obscure cases I have tried work -- no doubt I am not being devious
) enough. Can anyone else find one?

Make a loop where you define a VLA at the beginning, of differing size.
Also, in the same loop, alloca() some memory, (and store the pointer in
an array.)
Once a program uses alloca its behaviour is not governed by the C
standard alone. I could break VLAs with all sorts of stack-whacking
functions!
Of course, mixing VLA's and alloca() calls is nasty.
Is alloca() even part of C99 ?
No.

--
Ben.
Jul 20 '08 #14
On Sun, 20 Jul 2008 10:26:40 +0100, Ben Bacarisse wrote:
Ron Ford <ro*@nowhere.netwrites:
>On Sat, 19 Jul 2008 09:45:44 +0200, Joachim Schmitz posted:
>>Ron Ford wrote:
The development environment for gcc is austere.

gcc is not C99 compliant either.

How close is it?

Closer than even their own status pages suggests:

http://gcc.gnu.org/gcc-4.3/c99status.html

That reports wide character support as "missing" but as far as I can
tell, the only thing missing is format checking for the w* family
#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#include <wchar.h>

#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#if WE_HAVE_UNICODE && WE_DO_NOT_HAVE_UNICODE
#error Your compiler is broken.
#endif

int main() {}

I cannot get this to compile with GCC. Can you?

And yes, this matters, because you may very well want to do:

#if __STDC_ISO_10646__
#include <wchar.h>
#endif

which just doesn't work right now.
Jul 20 '08 #15
Willem wrote, On 20/07/08 10:30:
Ben Bacarisse wrote:
) VLAs are reported as broken, but I can't find an example of how. All
) the obscure cases I have tried work -- no doubt I am not being devious
) enough. Can anyone else find one?

Make a loop where you define a VLA at the beginning, of differing size.
Also, in the same loop, alloca() some memory, (and store the pointer in
an array.)

Of course, mixing VLA's and alloca() calls is nasty.
Is alloca() even part of C99 ?
No, alloca() is not part of any C standard, so using it does not really
prove that there is a problem.
--
Flash Gordon
Jul 20 '08 #16
Harald van Dijk <tr*****@gmail.comwrites:
On Sun, 20 Jul 2008 10:26:40 +0100, Ben Bacarisse wrote:
>Ron Ford <ro*@nowhere.netwrites:
>>On Sat, 19 Jul 2008 09:45:44 +0200, Joachim Schmitz posted:
Ron Ford wrote:
The development environment for gcc is austere.

gcc is not C99 compliant either.

How close is it?

Closer than even their own status pages suggests:

http://gcc.gnu.org/gcc-4.3/c99status.html

That reports wide character support as "missing" but as far as I can
tell, the only thing missing is format checking for the w* family

#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#include <wchar.h>

#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#if WE_HAVE_UNICODE && WE_DO_NOT_HAVE_UNICODE
#error Your compiler is broken.
#endif

int main() {}

I cannot get this to compile with GCC. Can you?
Well... you /can/ do this:

gcc -std=c99 -pedantic -include features.h

As far as I can see that does not break any conforming programs and
does make gcc closer to C99. It certainly then compiler the above
correctly.
And yes, this matters, because you may very well want to do:

#if __STDC_ISO_10646__
#include <wchar.h>
#endif
Agreed. It is a problem -- the above is the academic answer (and may
well break other areas of conformance). The macro should be defined
by -std=c99 alone.

--
Ben.
Jul 20 '08 #17
Ron Ford <ro*@nowhere.netwrote:
>
I wonder how closely the situation for compliance with F2003 compares to
C99. There seems to be one issue that has everyone stumped: parameterized
derived types. Of course, C won't have PDT's, but is there a single issue
that seems to have implementors pulling their hair out?
No, all of the major new features in C99 had already been implemented at
least once before the standard was approved. C99's problems are many:
lack of competition in the C compiler marketplace, lack of consumer
demand for full compliance, lack of resources (they're all busy trying
to implement C++), and incompatibility with existing extensions, just to
name a few big ones.
--
Larry Jones

How am I supposed to learn surgery if I can't dissect anything? -- Calvin
Jul 20 '08 #18
On Sun, 20 Jul 2008 12:42:36 +0200, Harald van Dijk posted:
On Sun, 20 Jul 2008 10:26:40 +0100, Ben Bacarisse wrote:
>Ron Ford <ro*@nowhere.netwrites:
>>On Sat, 19 Jul 2008 09:45:44 +0200, Joachim Schmitz posted:
Ron Ford wrote:
The development environment for gcc is austere.

gcc is not C99 compliant either.

How close is it?

Closer than even their own status pages suggests:

http://gcc.gnu.org/gcc-4.3/c99status.html

That reports wide character support as "missing" but as far as I can
tell, the only thing missing is format checking for the w* family

#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#include <wchar.h>

#if __STDC_ISO_10646__
#define WE_HAVE_UNICODE 1
#else
#define WE_DO_NOT_HAVE_UNICODE 1
#endif

#if WE_HAVE_UNICODE && WE_DO_NOT_HAVE_UNICODE
#error Your compiler is broken.
#endif

int main() {}

I cannot get this to compile with GCC. Can you?
I just fired this up in my new mingw IDE and got it to compile. I'm less
than surprised that it did, as it is my understanding that this is
equivalent to a hello world program, less the hello world:

http://i33.tinypic.com/wbxl54.jpg
>
And yes, this matters, because you may very well want to do:

#if __STDC_ISO_10646__
#include <wchar.h>
#endif

which just doesn't work right now.
Don't know about this.
--
Criticism is prejudice made plausible.
H. L. Mencken
Jul 20 '08 #19
On Sun, 20 Jul 2008 12:23:32 -0400, la************@siemens.com posted:
Ron Ford <ro*@nowhere.netwrote:
>>
I wonder how closely the situation for compliance with F2003 compares to
C99. There seems to be one issue that has everyone stumped: parameterized
derived types. Of course, C won't have PDT's, but is there a single issue
that seems to have implementors pulling their hair out?

No, all of the major new features in C99 had already been implemented at
least once before the standard was approved. C99's problems are many:
lack of competition in the C compiler marketplace, lack of consumer
demand for full compliance, lack of resources (they're all busy trying
to implement C++), and incompatibility with existing extensions, just to
name a few big ones.
I don't know what other syntaxes have standards other than C, C++ and
fortran, so I'm not sure how well a person can draw on the histories.
Since F2003 has a feature that has never been realized in fortran and it's
a stumbling block for *all* implementations, I wonder if it ever happens
that a standard rolls back on a feature.

The muckity mucks are enclaving to approve a new standard (F08) with *zero*
currently-conforming implementations. Has this situation ever occured in C
or some other standardized syntax?
--
There are men so philosophical that they can see humor in their own
toothaches. But there has never lived a man so philosophical that he could
see the toothache in his own humor.
H. L. Mencken
Jul 20 '08 #20
On Sun, 20 Jul 2008 10:11:58 +0100, Flash Gordon posted:
Ron Ford wrote, On 20/07/08 04:10:
>The above link is helpful. From Dann's link yesterday, I found Visual
MingW, which is an IDE for windows. I think that information might be
newer than the information on C's wiki page.
Please create an account and update anything that needs updating. It's a
Wiki and will only be as accurate and up to date as the last edit.
It doesn't augur well for my editting skills that I can't find a means to
create an account. In the text, there is to be some control to click on at
the top of the page that is not a control I could find.

I use wiki frequently and have wondered how to contribute. The latest
mistake I saw was in the wiki for the play "Bedroom Farce" where the
characters are characterized as "philanderers." There's a grand total of
one kiss exchanged in the entire play.
--
War will never cease until babies begin to come into the world with larger
cerebrums and smaller adrenal glands.
H. L. Mencken
Jul 20 '08 #21
Flash Gordon <sp**@flash-gordon.me.ukwrites:
Willem wrote, On 20/07/08 10:30:
>Ben Bacarisse wrote:
) VLAs are reported as broken, but I can't find an example of how. All
) the obscure cases I have tried work -- no doubt I am not being devious
) enough. Can anyone else find one?
Make a loop where you define a VLA at the beginning, of differing
size.
Also, in the same loop, alloca() some memory, (and store the pointer in
an array.)
Of course, mixing VLA's and alloca() calls is nasty.
Is alloca() even part of C99 ?

No, alloca() is not part of any C standard, so using it does not
really prove that there is a problem.
Well, it doesn't prove that there's a *conformance* problem. If a
compiler is going to support alloca(), it would be nice if using it
didn't break VLAs. But that might not be practical, and the standard
doesn't require it.

One possible issue with VLAs is that a VLA is block-scoped, not
function-scoped (which I think Willem was alluding to above) --
<OT>whereas the memory allocated by alloca() is deallocated on
returning from the enclosing function</OT>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 20 '08 #22
On Jul 19, 8:49*am, Ron Ford <r...@nowhere.netwrote:
I'm looking for a freeware c99 compiler for windows. *I had intended touse
MS's Visual C++ Express and use its C capability. *In the past with my MS
products, I've simply needed to make .c the filetype to invoke the C
compiler. *Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a compiler,
but then setup.exe wants to download 87 megs of dot net framework hoggs
that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to get the
shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?
You can try Eclipse and have the plug-in CDT (C/C++ Development Tool)
equipped together. The combination requires other compiler and
debugger.
Jul 21 '08 #23
Ron Ford <ro*@nowhere.netwrote:
>
I don't know what other syntaxes have standards other than C, C++ and
fortran, so I'm not sure how well a person can draw on the histories.
ADA, Algol, APL, Basic, COBOL, Modula-2, Pascal, and PL/I, just to name
a few.
Since F2003 has a feature that has never been realized in fortran and it's
a stumbling block for *all* implementations, I wonder if it ever happens
that a standard rolls back on a feature.
Yes, it happens, but it's very unusual.
The muckity mucks are enclaving to approve a new standard (F08) with *zero*
currently-conforming implementations. Has this situation ever occured in C
or some other standardized syntax?
Not in C, but I believe it has happened in C++ and probably in other
languages as well.
--
Larry Jones

I've never seen a sled catch fire before. -- Hobbes
Jul 21 '08 #24
On Sat, 19 Jul 2008 04:03:07 -0400, CBFalconer posted:
jacob navia wrote:
>Ron Ford wrote:
>>I'm looking for a freeware c99 compiler for windows. I had
intended to use MS's Visual C++ Express and use its C capability.
In the past with my MS products, I've simply needed to make .c
the filetype to invoke the C compiler. Here's a link

http://www.microsoft.com/express/download/#webInstall

The download is 2.6 megs, which is near a reasonable size for a
compiler, but then setup.exe wants to download 87 megs of dot net
framework hoggs that I don't want on my machine.

In the past I've gone with Bloodshed, but I find myself unable to
get the shell to stay open so I can see some output.

The development environment for gcc is austere.

Anyone have another suggestion?

Yes, use my compiler system lcc-win

The URL is below in my .sig.

Download 6MB.

If you (Ron Ford) do that be VERY cautious about portability. It
appears that lcc-win does not detect various forbidden constructs
under C99, besides omitting several required things. It will
probably improve, but the author tends to resist suggestions. I
believe it also lacks version numbers, making it hard to keep track
of revisions.


I've used Jacob's lcc before and profited from it. At the time, I was
realizing that MVC6 wasn't going to do a lot of the things that I wanted
from a C99 compiler. Lcc helped me understand what I was looking for. In
particular, I remember finding the appropriate headers there for the first
time.

Meanwhile, Jacob has become less popular in clc, which I didn't think was
possible, and I've seen posts of his that looked angry and deranged, if not
drunk. For the record, I just wanted to state that the reason I didn't
download lcc was that I couldn't imagine wanting to admit to having a
problem and having to disclose that I was using lcc. I don't mean this as
a personal attack on Jacob, but I hope that he knows I like Frenchmen a
hell of lot better than my butthead Texas neighbors.

Another reason that I didn't go with lcc is that I'm looking for a compiler
for a specific purpose and think I've found a winner with WINAVR from
Atmel:

2.1 Manifest

GNU Binutils 2.18
Binary utilities for AVR target (including assembler, linker, etc.).

GNU Compiler Collection (GCC) 4.3.0
C language and C++ language compiler for AVR target. There are
caveats for using the C++ compiler. See the installed avr-libc
User Manual in the <InstallDir>\doc directory.

avr-libc CVS snapshot (1.6 branch, post 1.6.2)
C Standard Library for AVR.

AVR-Ada 0.5.2
Run Time System for the Ada compiler.
(Removed temporarily)

AVRDUDE 5.5
avrdude is an open source programmer software that is user extensible.

GNU Debugger (GDB) / Insight 6.6
GDB is a command-line debugger. Insight is GDB with a GUI!

AVaRICE 2.7
avarice is a program for interfacing the Atmel JTAG ICE to GDB and users
can debug their AVR. Use it in conjunction with GDB.

SimulAVR 0.1.2.5
simulavr is used in conjunction with GDB to provide AVR simulation.

SRecord 1.38
SRecord is a collection of powerful tools for manipulating EPROM load
files.
It reads and writes numerous EPROM file formats, and can perform many
different manipulations.

MFile
An automatic makefile generator for AVR GCC.

Programmers Notepad 2.0.7.667-devel
Programming editor and IDE. This editor includes the Scintilla editor
component.

//end abridged manifest

For interested parties:
http://winavr.sourceforge.net/
--
We must be willing to pay a price for freedom.
H. L. Mencken
Jul 22 '08 #25
Ron Ford wrote:
[snip]
>
I've used Jacob's lcc before and profited from it. At the time, I was
realizing that MVC6 wasn't going to do a lot of the things that I wanted
from a C99 compiler. Lcc helped me understand what I was looking for. In
particular, I remember finding the appropriate headers there for the first
time.
OK, so you used my work and it was useful for you. Nice.
Meanwhile, Jacob has become less popular in clc, which I didn't think was
possible,
Why should I be popular with the "regulars" here? I am completely
opposed to that people.
and I've seen posts of his that looked angry and deranged, if not
drunk.
An example of a "drunk" post is yours. See below.
For the record, I just wanted to state that the reason I didn't
download lcc was that I couldn't imagine wanting to admit to having a
problem and having to disclose that I was using lcc.
So, since I am not "popular" with the regulars here, you are afraid
of "disclosing" that my work was useful to you. You fear that the
regulars will leave you out in the cold, poor soul...
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 22 '08 #26
In article <g6**********@aioe.org>, jacob navia <ja***@nospam.orgwrote:
>Ron Ford wrote:
....
>For the record, I just wanted to state that the reason I didn't
download lcc was that I couldn't imagine wanting to admit to having a
problem and having to disclose that I was using lcc.

So, since I am not "popular" with the regulars here, you are afraid
of "disclosing" that my work was useful to you. You fear that the
regulars will leave you out in the cold, poor soul...
That *is* basically what it boils down to. Assuming that you
(hypothetical "you") are so desperate for help (say, to escape brutal
third world squalor) that you're willing to take it from the jerks of
CLC, then it *is* in your interest to not be seen as being friendly with
Jacob. The regs will not look kindly upon that.

All of life is just the grade school playground. Most of us never
mature beyond that point. And CLC is demonstrable proof of this.

Jul 22 '08 #27
On Tue, 22 Jul 2008 16:13:22 +0000 (UTC), Kenny McCormack posted:
In article <g6**********@aioe.org>, jacob navia <ja***@nospam.orgwrote:
>>Ron Ford wrote:
...
>>For the record, I just wanted to state that the reason I didn't
download lcc was that I couldn't imagine wanting to admit to having a
problem and having to disclose that I was using lcc.

So, since I am not "popular" with the regulars here, you are afraid
of "disclosing" that my work was useful to you. You fear that the
regulars will leave you out in the cold, poor soul...

That *is* basically what it boils down to. Assuming that you
(hypothetical "you") are so desperate for help (say, to escape brutal
third world squalor) that you're willing to take it from the jerks of
CLC, then it *is* in your interest to not be seen as being friendly with
Jacob. The regs will not look kindly upon that.

All of life is just the grade school playground. Most of us never
mature beyond that point. And CLC is demonstrable proof of this.
I don't fear disclosing that Jacob's work has been useful to me. I just
did.

My current project has to do with embedded systems, and lcc isn't the best
tool.

If clc were a playground soccer game, Jacob would be my first pick.
--
In this world of sin and sorrow there is always something to be thankful
for; as for me, I rejoice that I am not a Republican.
H. L. Mencken
Jul 23 '08 #28
Ron Ford said:

<snip>
If clc were a playground soccer game, Jacob would be my first pick.
Really? Mine would be Chris Torek.

If, on the other hand, it were a basketball game, it would all depend on
who were refereeing. ("I tried it and it worked fine...")

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 23 '08 #29
On Wed, 23 Jul 2008 01:41:08 +0000, Richard Heathfield posted:
Ron Ford said:

<snip>
>If clc were a playground soccer game, Jacob would be my first pick.

Really? Mine would be Chris Torek.
Dude, I've played soccer in SLC and can assure you that Torek would have to
be a goalie, if Keith didn't antecedently have to be.

But since you chose a player, I'll use the ISO_C_BINDING and select Richard
Maine from a common extension.
>
If, on the other hand, it were a basketball game, it would all depend on
who were refereeing. ("I tried it and it worked fine...")
I'm gonna guess that I'm the only fella in clc who can dunk it. South
Chicago.
--
What men value in this world is not rights but privileges.
H. L. Mencken
Jul 23 '08 #30
Ron Ford said:
On Wed, 23 Jul 2008 01:41:08 +0000, Richard Heathfield posted:
>Ron Ford said:

<snip>
>>If clc were a playground soccer game, Jacob would be my first pick.

Really? Mine would be Chris Torek.

Dude, I've played soccer in SLC and can assure you that Torek would have
to be a goalie, if Keith didn't antecedently have to be.

But since you chose a player, I'll use the ISO_C_BINDING and select
Richard Maine from a common extension.
>>
If, on the other hand, it were a basketball game, it would all depend on
who were refereeing. ("I tried it and it worked fine...")

I'm gonna guess that I'm the only fella in clc who can dunk it. South
Chicago.

I understood every individual word in your reply; nevertheless, I didn't
understand a single word of it.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 23 '08 #31
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:tf******************************@bt.com...
Ron Ford said:

<snip>
>If clc were a playground soccer game, Jacob would be my first pick.

Really? Mine would be Chris Torek.
You guys are nuts. I'm going with Pele in his prime.
;-)

** Posted from http://www.teranews.com **
Jul 23 '08 #32
On Wed, 23 Jul 2008 00:09:58 -0700, Dann Corbit posted:
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:tf******************************@bt.com...
>Ron Ford said:

<snip>
>>If clc were a playground soccer game, Jacob would be my first pick.

Really? Mine would be Chris Torek.

You guys are nuts. I'm going with Pele in his prime.
;-)
Maradonna was the best I ever saw. It's interesting to think of what a
soccer game with clc would look like, but it is a sheer impossibility to
have a casual ballgame among persons who would have to burn an average of a
hundred gallons of fossil fuel to attend.

I think the etymology of "Torek" might actually be close to goalie. The
-ik, uk, ek ending indicates "one who does" in languages like Russian and
Polish. "Tor" could be gate or goal.

Regarding basketball, Barack Omaba is not an unusual Chicagoan to be able
to hit a three-pointer. It speaks to his poise, athleticism and
flexibility that he could go one for one from beyond the arc. My brother
hits from farther out, truly downtown, routinely.
>
** Posted from http://www.teranews.com **
Dann, did you change your NSP? I had a google killfilter that was hiting
your posts before.

--
War will never cease until babies begin to come into the world with larger
cerebrums and smaller adrenal glands. 2
H. L. Mencken
Jul 24 '08 #33
>>Ron Ford said:
>>>If clc were a playground soccer game, Jacob would be my first pick.
>"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:tf******************************@bt.com...
>>Really? Mine would be Chris Torek.
>On Wed, 23 Jul 2008 00:09:58 -0700, Dann Corbit posted:
>You guys are nuts. I'm going with Pele in his prime.
;-)
In article <ri***************************@40tude.net>
Ron Ford <ro*@nowhere.netwrote:
>I think the etymology of "Torek" might actually be close to goalie.
The word "torek" in Slovenian means "tuesday", apparently. The
name also fits the pattern of Vulcan names, which is perhaps more
appropriate. :-)

If I were to play soccer, goalie might be the most appropriate
position anyway, as I have a bad knee (left leg) and a bad foot
(right leg) thanks to getting hit by a car. (I was in a crosswalk
-- Richard Heathfield would call it a zebra crossing -- at a four-way
stop; the driver was in a 1974 Toyota Land Cruiser.) The main side
effect of these today is that I cannot do "high impact" aerobics,
and have to wear knee wraps when doing squats with anything over
about 250 pounds.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jul 26 '08 #34
Chris Torek said:

<snip>
In article <ri***************************@40tude.net>
Ron Ford <ro*@nowhere.netwrote:
>>I think the etymology of "Torek" might actually be close to goalie.

The word "torek" in Slovenian means "tuesday", apparently. The
name also fits the pattern of Vulcan names, which is perhaps more
appropriate. :-)
In Polish (another Slavic language), "Tuesday" is "wtorek" - pretty close.
Oh, and "torebka" means "bag". :-)

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 26 '08 #35
On 24 Jul 2008 at 20:32, Ron Ford wrote:
It's interesting to think of what a soccer game with clc would look
like
Given that clc is full of egomaniacs, it's hard to imagine finding 11 of
them that could play as a team for 90 minutes without ripping each other
to shreds.

But my money would be on CBF scoring an awful lot of own goals.

Jul 26 '08 #36
On Sun, 20 Jul 2008 12:34:03 +0100, Ben Bacarisse wrote:
Well... you /can/ do this:

gcc -std=c99 -pedantic -include features.h

As far as I can see that does not break any conforming programs and
does make gcc closer to C99. It certainly then compiler the above
..SNIP...

I write network programs and yes I uses Sockets all the time. I mainly
use it because of 3 reasons:

1.) // style comments
2.) for( int i = 0; ... ) , to keep i localized to the loop
3.) snprintf (replacement for sprintf)
Regarding portability, I am focused on Linux only. I don't work on any
other OS. So, Do you guys advise to use -std=c99 as compiler option ?


--
www.lispmachine.wordpress.com
my email is @ the above blog
check the "About Myself" page

Aug 4 '08 #37
arnuld wrote:
>On Sun, 20 Jul 2008 12:34:03 +0100, Ben Bacarisse wrote:
>Well... you /can/ do this:

gcc -std=c99 -pedantic -include features.h

As far as I can see that does not break any conforming programs and
does make gcc closer to C99. It certainly then compiler the above
>..SNIP...


I write network programs and yes I uses Sockets all the time. I mainly
use it because of 3 reasons:

1.) // style comments
2.) for( int i = 0; ... ) , to keep i localized to the loop
3.) snprintf (replacement for sprintf)
Regarding portability, I am focused on Linux only. I don't work on any
other OS. So, Do you guys advise to use -std=c99 as compiler option ?
If you focused only on Linux you might as well take advantage of gcc
specific, Linux specific and POSIX extensions. For gcc
use '-std=gnu99'. It might still be useful to keep portable and
non-portable functionality separate, in case you ever change your mind.

Look-up the "feature test macros" functionality of GNU libc. The POSIX
documentation is also freely available online. For more details go to
comp.unix.programmer and comp.os.linux.development.[apps/system].

Aug 4 '08 #38
On Mon, 04 Aug 2008 17:47:38 +0530, santosh wrote:
arnuld wrote:
>I write network programs and yes I uses Sockets all the time. I mainly
use it because of 3 reasons:

1.) // style comments
2.) for( int i = 0; ... ) , to keep i localized to the loop
3.) snprintf (replacement for sprintf)

Regarding portability, I am focused on Linux only. I don't work on any
other OS. So, Do you guys advise to use -std=c99 as compiler option ?

If you focused only on Linux you might as well take advantage of gcc
specific,
To both arnuld and santosh: please don't assume that everyone on Linux
uses gcc. At the very least, there's Intel's compiler, but there are other
useful compilers as well.
Linux specific and POSIX extensions.
Fair enough.
For gcc use '-std=gnu99'.
I would recommend sticking with -std=c99. Even if you want to make use of
GNU-specific features, you can use -std=c99; you'll usually just need to
either deal with warnings or clearly mark your use of extensions. This, in
my opinion, is a good thing.
It might still be useful to keep portable and non-portable functionality
separate, in case you ever change your mind.
Well, we had similar ideas apparently, but different methods.
Look-up the "feature test macros" functionality of GNU libc. The POSIX
documentation is also freely available online. For more details go to
comp.unix.programmer and comp.os.linux.development.[apps/system].
Aug 4 '08 #39
arnuld wrote:
>Ben Bacarisse wrote:
>Well... you /can/ do this:

gcc -std=c99 -pedantic -include features.h

As far as I can see that does not break any conforming programs
and does make gcc closer to C99. It certainly then compiler the
above
>..SNIP...

I write network programs and yes I uses Sockets all the time. I
mainly use it because of 3 reasons:

1.) // style comments
2.) for( int i = 0; ... ) , to keep i localized to the loop
3.) snprintf (replacement for sprintf)

Regarding portability, I am focused on Linux only. I don't work
on any other OS. So, Do you guys advise to use -std=c99 as
compiler option ?
You are much more portable relying on the C90 standard. The result
is almost always compatible with C99 (the only exception I know of
has to do with the modulus operator and negative values). You
can't use the // comments, but that is no loss IMO.

With gcc, I habitually use:
-W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal -ftrapv ...

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Aug 4 '08 #40
On Mon, 04 Aug 2008 16:47:21 -0400, CBFalconer wrote:

You are much more portable relying on the C90 standard. The result
is almost always compatible with C99 (the only exception I know of
has to do with the modulus operator and negative values). You
can't use the // comments, but that is no loss IMO.
what about snprintf, which saves from overflowing the array attacks. And
what about localization of index integers like for( in i = 0...) .

I know you are trying to help me, what I am saying that the softwares I am
paid to write for are designed only to run on Linux and nothing else.

With gcc, I habitually use:
-W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal -ftrapv ...
Doesn't -Wextra give access to -Wwrite-strings and -Wfloat-equal ?

--
www.lispmachine.wordpress.com
my email is @ the above blog
check the "About Myself" page

Aug 5 '08 #41
On Mon, 04 Aug 2008 21:23:09 +0200, Harald van Dijk wrote:

To both arnuld and santosh: please don't assume that everyone on Linux
uses gcc. At the very least, there's Intel's compiler, but there are
other useful compilers as well.
Exactly. And the focus I am paid for is Linux & GCC centric.

I would recommend sticking with -std=c99. Even if you want to make use
of GNU-specific features, you can use -std=c99; you'll usually just need
to either deal with warnings or clearly mark your use of extensions.
This, in my opinion, is a good thing.

That seems like a sound advice ;)
--
www.lispmachine.wordpress.com
my email is @ the above blog
check the "About Myself" page

Aug 5 '08 #42
arnuld said:
>On Mon, 04 Aug 2008 16:47:21 -0400, CBFalconer wrote:

>You are much more portable relying on the C90 standard. The result
is almost always compatible with C99 (the only exception I know of
has to do with the modulus operator and negative values). You
can't use the // comments, but that is no loss IMO.

what about snprintf, which saves from overflowing the array attacks.
Using snprintf does not guarantee this. You have to use it /properly/. And
if you use sprintf properly, you get the same safety. So snprintf isn't
actually all that big a deal.

But it seems from other stuff you've said that you're only interested in
Linux, which is fine, but it does suggest that you'd be better off asking
about flags in a group dealing with your implementation rather than a
group dealing with the C language.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 5 '08 #43
Richard Heathfield wrote:
arnuld said:
<snip>
>what about snprintf, which saves from overflowing the array attacks.

Using snprintf does not guarantee this. You have to use it /properly/.
And if you use sprintf properly, you get the same safety. So snprintf
isn't actually all that big a deal.
Well, the difference is that with snprintf, as long as the second
parameter is correct you are guaranteed to avoid a buffer overrun,
while with sprintf you need to be sure in advance that the second
argument will not overrun the first, and this could be quite difficult
in some cases.

<snip>

Aug 5 '08 #44
santosh said:
Richard Heathfield wrote:
>arnuld said:

<snip>
>>what about snprintf, which saves from overflowing the array attacks.

Using snprintf does not guarantee this. You have to use it /properly/.
And if you use sprintf properly, you get the same safety. So snprintf
isn't actually all that big a deal.

Well, the difference is that with snprintf, as long as the second
parameter
(You mean the second argument expression, presumably.)
is correct you are guaranteed to avoid a buffer overrun,
No, you're not, because your /first/ argument could be incorrect:

#define OOPS 6

char intended[32] = {0};
char actual[OOPS] = {0};

snprintf(actual, sizeof intended, "Hello, world");

or your copying semantics might be screwed:

snprintf(ohdear, sizeof ohdear, "%d: %s", i, ohdear);

(in which case the behaviour is undefined, and one possible outcome of
undefined behaviour is that a buffer overrun occurs).
while with sprintf you need to be sure in advance that the second
argument will not overrun the first, and this could be quite difficult
in some cases.
You need to be sure with snprintf too, otherwise you'll silently lose data.
No, it doesn't have to be silent, because you could be listening - but by
the time you've taken the trouble to add the code to listen for data loss
and take corrective action to ensure that no data loss occurs after all,
you might as well have used sprintf in the first place.

Arbitrary data loss might be okay for some people, but it's something I try
to avoid if I can.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 5 '08 #45
Richard Heathfield wrote:
santosh said:
>Richard Heathfield wrote:
>>arnuld said:

<snip>
>>>what about snprintf, which saves from overflowing the array
attacks.

Using snprintf does not guarantee this. You have to use it
/properly/. And if you use sprintf properly, you get the same
safety. So snprintf isn't actually all that big a deal.

Well, the difference is that with snprintf, as long as the second
parameter

(You mean the second argument expression, presumably.)
>is correct you are guaranteed to avoid a buffer overrun,

No, you're not, because your /first/ argument could be incorrect:
Yes. But when I said "correct" I meant that it was the correct value for
the first argument. I realise in hindsight that I should've explicitly
mentioned this.
#define OOPS 6

char intended[32] = {0};
char actual[OOPS] = {0};

snprintf(actual, sizeof intended, "Hello, world");
The second argument is "wrong", isn't it? :-)
or your copying semantics might be screwed:

snprintf(ohdear, sizeof ohdear, "%d: %s", i, ohdear);

(in which case the behaviour is undefined, and one possible outcome of
undefined behaviour is that a buffer overrun occurs).
Agreed.
>while with sprintf you need to be sure in advance that the second
argument will not overrun the first, and this could be quite
difficult in some cases.

You need to be sure with snprintf too, otherwise you'll silently lose
data.
But this is, in most cases, better than invoking undefined behaviour
with a buffer overrun, since it's possible to recover and retry.
No, it doesn't have to be silent, because you could be listening
- but by the time you've taken the trouble to add the code to listen
for data loss and take corrective action to ensure that no data loss
occurs after all,
Exactly.
you might as well have used sprintf in the first place.
But the difference is that with sprintf you need to know this in
advance, while with snprintf you can "adapt as you go", so to speak.
This offloads the tricky bit of figuring out exactly how long our
buffer needs to be to snprintf itself.
Arbitrary data loss might be okay for some people, but it's something
I try to avoid if I can.
One can use snprintf *and* avoid arbitrary data loss. You need to cache
all your arguments beyond the first, determine the buffer size needed
by a call to snprintf, malloc the buffer (or perhaps a VLA), and write
to it. I admit that this is more complicated than one would like, but
sprintf, by overrunning the buffer, invokes a problem that cannot be
recovered from with Standard C.

Both are perfectly usable if adequate care is taken, but snprintf does
add a small convenience that I personally like. And it's certainly
among the more widely implemented of C99's many additions.

Aug 5 '08 #46
On Aug 4, 3:47 pm, CBFalconer <cb********@yahoo.comwrote:
arnuld wrote:
Ben Bacarisse wrote:
Well... you /can/ do this:
gcc -std=c99 -pedantic -include features.h
As far as I can see that does not break any conforming programs
and does make gcc closer to C99. It certainly then compiler the
above
..SNIP...
I write network programs and yes I uses Sockets all the time. I
mainly use it because of 3 reasons:
1.) // style comments
2.) for( int i = 0; ... ) , to keep i localized to the loop
3.) snprintf (replacement for sprintf)
Regarding portability, I am focused on Linux only. I don't work
on any other OS. So, Do you guys advise to use -std=c99 as
compiler option ?

You are much more portable relying on the C90 standard. The result
is almost always compatible with C99 (the only exception I know of
has to do with the modulus operator and negative values).
Here are others:

o No implicit function declarations (so you can't use a function
without defining or declaring it first)
o No implicit function return type (so you can't omit the return
type of a function and let it default to int)
o It's illegal to have a return statement with no expression in
a non-void function (in previous versions this would cause
undefined behavior)

Just to name the most obvious ones...
You
can't use the // comments, but that is no loss IMO.
One man's trash is another man's treasure :) That's one of the BIGGEST
losses, IMO (along with being unable to mix statements and
declarations).

<snip>

Anyway, I don't see any portability losses if you're working on common
platforms, let alone if you're working on a *single* platform, not to
mention if that platform happens to be Linux!

Sebastian

Aug 5 '08 #47
santosh said:
Richard Heathfield wrote:
>santosh said:
<snip>
>>Well, the difference is that with snprintf, as long as the second
parameter

(You mean the second argument expression, presumably.)
>>is correct you are guaranteed to avoid a buffer overrun,

No, you're not, because your /first/ argument could be incorrect:

Yes. But when I said "correct" I meant that it was the correct value for
the first argument. I realise in hindsight that I should've explicitly
mentioned this.
>#define OOPS 6

char intended[32] = {0};
char actual[OOPS] = {0};

snprintf(actual, sizeof intended, "Hello, world");

The second argument is "wrong", isn't it? :-)
The intended line is:

snprintf(intended, sizeof intended, "Hello, world");

so it's the first arg, not the second, that needs to be corrected. My
point, which is now in danger of being concealed by good-humoured banter,
is that there are almost always several ways to get things wrong.

<snip>
>>while with sprintf you need to be sure in advance that the second
argument will not overrun the first, and this could be quite
difficult in some cases.

You need to be sure with snprintf too, otherwise you'll silently lose
data.

But this is, in most cases, better than invoking undefined behaviour
with a buffer overrun, since it's possible to recover and retry.
Better surely to do neither, but to get it right first time instead.
>No, it doesn't have to be silent, because you could be listening
- but by the time you've taken the trouble to add the code to listen
for data loss and take corrective action to ensure that no data loss
occurs after all,

Exactly.
>you might as well have used sprintf in the first place.

But the difference is that with sprintf you need to know this in
advance, while with snprintf you can "adapt as you go", so to speak.
Mostly you do know in advance. On the rare occasions when you don't, it's
generally easy enough to find out.
This offloads the tricky bit of figuring out exactly how long our
buffer needs to be to snprintf itself.
The way I see it is that if you know that your buffer is already long
enough, you don't need to offload this figuring because it's already done.
And if it isn't long enough (or at least you don't know whether it is),
you're not ready to construct the output yet, and so you're not really
using snprintf as a string-builder but as a calculator, after which you
must allocate storage for the buffer - which you *now* know *for sure* is
long enough, right? And so you might as well use sprintf for the final
stage of building the string.
>Arbitrary data loss might be okay for some people, but it's something
I try to avoid if I can.

One can use snprintf *and* avoid arbitrary data loss.
Yes, but you can say that about almost any function - for example, you can
use isalpha and avoid arbitrary data loss. The point is that snprintf is
wrongly touted as a "safe" alternative to sprintf whereas in fact it is no
such thing (much as strncpy is falsely touted as a "safe" alternative to
strcpy).

You need to cache
all your arguments beyond the first, determine the buffer size needed
by a call to snprintf, malloc the buffer (or perhaps a VLA), and write
to it. I admit that this is more complicated than one would like, but
sprintf, by overrunning the buffer, invokes a problem that cannot be
recovered from with Standard C.
To use sprintf safely, you first need to find out how big your output
buffer needs to be - and once you've done that, it's just as safe as
snprintf and considerably more portable.
Both are perfectly usable if adequate care is taken,
Right.
but snprintf does
add a small convenience that I personally like. And it's certainly
among the more widely implemented of C99's many additions.
If you know for sure that all your target platforms support it (with the
same semantics on each platform), that's a perfectly sensible approach. I
just can't help thinking that it's a risky strategy, that's all - stuff we
know "for sure" has an alarming habit of turning out not to be true in six
months time.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 5 '08 #48
On Tue, 05 Aug 2008 10:58:20 +0000, Richard Heathfield wrote:
Using snprintf does not guarantee this. You have to use it /properly/. And
if you use sprintf properly, you get the same safety. So snprintf isn't
actually all that big a deal.
Aye.. did not know that :( , will check archives first and then ask

But it seems from other stuff you've said that you're only interested in
Linux, which is fine, but it does suggest that you'd be better off asking
about flags in a group dealing with your implementation rather than a
group dealing with the C language.
oops!
--
www.lispmachine.wordpress.com
my email is @ the above blog
check the "About Myself" page

Aug 5 '08 #49
On Tue, 05 Aug 2008 10:58:20 +0000, Richard Heathfield wrote:

Using snprintf does not guarantee this. You have to use it /properly/.
And if you use sprintf properly, you get the same safety. So snprintf
isn't actually all that big a deal.
I searched the archives and really much confused. "Ben Pfaff" says:

The point is that strncpy() is as dangerous
as strcpy() if it isn't used with care.
and regarding sprintf vs snprint I get this from "Aleksander Nabaglo"

1: Calculate needed buffer size,
2: Use assert: bug will not be hidden.
int nsp=0;

sprintf(buf, " ..... %n", /* args */ , &nsp);
if(buf_size <= nsp) { assert(0 & " buf[] too short ");
exit(SOME_ERROR_CODE);

is that okay ?
I also heard from someone that using assert() in code going to be shipped
is a bad idea. All assert statement, before the delivery, must be removed.

Do you have some code for safe sprintf() ?

But it seems from other stuff you've said that you're only interested in
Linux, which is fine,
I actually thought snprint() will save me from buffer problems and now
after a little search I can see that I was using it blindly. Anyway, I
still like the for( int i = 0;..) localization in C99. I don't like my
programs to be polluted by some index numbers when I know I am on Linux
for next decade, at least.

--
www.lispmachine.wordpress.com
my email is @ the above blog
check the "About Myself" page

Aug 5 '08 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.