473,405 Members | 2,176 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,405 software developers and data experts.

Not quite standard... but socially acceptable

I mainly keep my code as standard as possible, but I need to branch
out just a tad.

Firstly, if you're writing console programs for a system that has a
screen, a keyboard, and a commandline, then is there any commonly used
library for doing things like clearing the screen, or taking a single
key press from the user?

Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.
Apr 3 '08 #1
14 1250
Tomás Ó hÉilidhe wrote:
I mainly keep my code as standard as possible, but I need to branch
out just a tad.

Firstly, if you're writing console programs for a system that has a
screen, a keyboard, and a commandline, then is there any commonly used
library for doing things like clearing the screen, or taking a single
key press from the user?
It depends if you want the unix flavor, or the windows flavor
Unix uses a "curses" library to control the screen/keyboard.

Under windows most compilers provide
keypressed()

or similar stuff.

Under windows Microsoft provides a Console API that does all the
console handling (console colors, reading text from the console, etc)
Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.
This is standard C. The standard allows explicitly to declare variables
anywhere.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 3 '08 #2
Tomás Ó hÉilidhe <to*@lavabit.comwrites:
Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.
C99 no longer requires all declarations to be at the beginning of
a block. Perhaps you can require some level of C99 conformance
from the compilers that you support.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
Apr 3 '08 #3
jacob navia <ja***@nospam.comwrites:
Tomás Ó hÉilidhe wrote:
[...]
>Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.

This is standard C. The standard allows explicitly to declare variables
anywhere.
What jacob isn't bothering to tell you is that this is a new feature
in the current C standard, issued in 1999 (and therefore referred to
as "C99"). Most C compilers do not yet fully support the C99
standard; they instead support the earlier C90 or C95 standard (C95
was a minor update to C90).

I won't tell you that you shouldn't use C99-specific features. I will
tell you that, by doing so, you risk limiting the portability of your
code (a risk that, I hope, will diminish over time).

If you want maximal portability, you can program in the common subset
of C90 and C99 (basically C90 without implicit int and without trying
to use the few new keywords as identifiers).

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 3 '08 #4
Keith Thompson wrote:
jacob navia <ja***@nospam.comwrites:
>Tomás Ó hÉilidhe wrote:
[...]
>>Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.
This is standard C. The standard allows explicitly to declare variables
anywhere.

What jacob isn't bothering to tell you is that this is a new feature
in the current C standard, issued in 1999 (and therefore referred to
as "C99").
Can't you read man?

I said:
This is standard C. The standard allows explicitly to declare variables
anywhere.

"New" was in 1999, or maybe 2003...
In 2008 is no longer "new". Besides, as the OP says:
>>[snip] ... I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
So, it more common than what you think
Most C compilers do not yet fully support the C99
standard; they instead support the earlier C90 or C95 standard (C95
was a minor update to C90).
Most of them support this feature, as the OP says.

I won't tell you that you shouldn't use C99-specific features. I will
tell you that, by doing so, you risk limiting the portability of your
code (a risk that, I hope, will diminish over time).
The OP did not mention any portability requirements
other than "socially acceptable".
If you want maximal portability, you can program in the common subset
of C90 and C99 (basically C90 without implicit int and without trying
to use the few new keywords as identifiers).
By using standard C you promote the standard. I think it should
be done.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 3 '08 #5
jacob navia wrote:
Tomás Ó hÉilidhe wrote:
>Firstly, if you're writing console programs for a system that
has a screen, a keyboard, and a commandline, then is there any
commonly used library for doing things like clearing the screen,
or taking a single key press from the user?

It depends if you want the unix flavor, or the windows flavor
Unix uses a "curses" library to control the screen/keyboard.

Under windows most compilers provide keypressed()
These things are system specific, and discussion belongs on system
specific newsgroups. They are off-topic here.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Apr 3 '08 #6
jacob navia <ja***@nospam.comwrites:
Keith Thompson wrote:
>jacob navia <ja***@nospam.comwrites:
>>Tomás Ó hÉilidhe wrote:
[...]
>>>Secondly, is it OK, do you think, to flout C's rule of having to
define all objects at the beginning of a block? I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,
and I think it leads to far neater code, especially when it comes to
being able to use const in places where you previously weren't able.
This is standard C. The standard allows explicitly to declare variables
anywhere.

What jacob isn't bothering to tell you is that this is a new feature
in the current C standard, issued in 1999 (and therefore referred to
as "C99").

Can't you read man?
Yes, I can. Can you?
I said:
This is standard C. The standard allows explicitly to declare variables
anywhere.
Yes, that's true, and I said nothing that contradicts that.
"New" was in 1999, or maybe 2003...
In 2008 is no longer "new". Besides, as the OP says:
As long as the C99 standard is less widely supported than the C90
standard, it's *effectively* new, regardless of its chronological age.
>>>[snip] ... I've seen that a hell
of a lot of C compilers allow you to define objects wherever you want,

So, it more common than what you think
That particular feature is fairly common, yes. I didn't say it
wasn't.
>Most C compilers do not yet fully support the C99
standard; they instead support the earlier C90 or C95 standard (C95
was a minor update to C90).

Most of them support this feature, as the OP says.
I didn't say otherwise.
>I won't tell you that you shouldn't use C99-specific features. I will
tell you that, by doing so, you risk limiting the portability of your
code (a risk that, I hope, will diminish over time).

The OP did not mention any portability requirements
other than "socially acceptable".
The OP seemed to be under the impression that mixing declarations and
statements within a block is a common, but non-standard, extension.

You just told him that it's "standard C", which is quite correct but
incomplete. I provided more information. Why do you have a problem
with that?
>If you want maximal portability, you can program in the common subset
of C90 and C99 (basically C90 without implicit int and without trying
to use the few new keywords as identifiers).

By using standard C you promote the standard. I think it should
be done.
So promote the standard. I have no problem with that.

It is a fact (unfortunately) that C99 is not yet as widely supported
as C90. I conveyed that information to the OP, who can use it in
whatever way he chooses. I didn't even disagree with anything you
wrote. If you have a problem with that, that's just too bad.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 3 '08 #7
On Thu, 03 Apr 2008 13:13:02 -0700, Keith Thompson wrote:
What jacob isn't bothering to tell you is that this is a new feature in
the current C standard, issued in 1999 (and therefore referred to as
"C99"). Most C compilers do not yet fully support the C99 standard;
they instead support the earlier C90 or C95 standard (C95 was a minor
update to C90).
What exactly do you mean by "most C compilers"? Are we talking about the
number of makes and models released or are we talking about install base?
Rui Maciel
Apr 4 '08 #8
Rui Maciel <ru********@gmail.comwrites:
On Thu, 03 Apr 2008 13:13:02 -0700, Keith Thompson wrote:
>What jacob isn't bothering to tell you is that this is a new feature in
the current C standard, issued in 1999 (and therefore referred to as
"C99"). Most C compilers do not yet fully support the C99 standard;
they instead support the earlier C90 or C95 standard (C95 was a minor
update to C90).

What exactly do you mean by "most C compilers"? Are we talking about the
number of makes and models released or are we talking about install base?
Take your pick. As far as I know, full C99 support is rare by either
measure.

And just in case anyone thinks I'm attacking the C99 standard, I wish
this were not the case. (This is not directed at you, Rui.)

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 4 '08 #9
On Fri, 04 Apr 2008 17:23:03 +0000, Richard Heathfield wrote:
Which compiler that I use did you have in mind? gcc? Microsoft Visual C?
Borland C? LE370? C/370? CodeWarrior? Much of my code has to port *not
only* to all of these compilers (none of which currently conform to
C99), but also (in some cases) *any* other conforming C compiler.

When *all* my users' compilers support C99, that will be the time to
switch. At present, as far as I am aware, none of my users' compilers
conform to C99[1], so there is still a little way to go.
Correct me if I'm wrong but that doesn't mean that the C99 standard isn't
portable. That just means that you are forced to work with some compilers
that don't comply with the C99 standard.
Rui Maciel
Apr 4 '08 #10
In article <47***********************@news.telepac.pt>,
Rui Maciel <ru********@gmail.comwrote:
>Correct me if I'm wrong but that doesn't mean that the C99 standard isn't
portable. That just means that you are forced to work with some compilers
that don't comply with the C99 standard.
Can a standard really be considered portable if no major compiler
implements it?
dave

--
Dave Vandervies dj3vande at eskimo dot com
If you plan on working in some sort of Bond-esque, fusion-powered laser
death ray, count me in as an investor.
--Abby in uw.general
Apr 4 '08 #11
Rui Maciel said:
On Fri, 04 Apr 2008 17:23:03 +0000, Richard Heathfield wrote:
<snip>
>At present, as far as I am aware, none of my users' compilers
conform to C99[1], so there is still a little way to go.

Correct me if I'm wrong but that doesn't mean that the C99 standard isn't
portable. That just means that you are forced to work with some compilers
that don't comply with the C99 standard.
Well, "portable" isn't a binary concept, I agree - it isn't that code
written to a given Standard either is, or is not, portable. Rather, the
degree of portability of a program can be measured by the number of
different conforming implementations on which it works unmodified. (That
isn't the only measure, of course, but it's the one I use.)

At present, I am writing code that is, for my purposes at least, maximally
portable - that is, it works unmodified on all the implementations on
which my users compile it (in conforming mode). If I adopt your suggestion
and start using C99isms, suddenly it won't compile *anywhere* (or, at
least, hardly anywhere). "Not compiling" is *not* what *I* mean by the
word "portable". And I am *not* going to ask my users to invoke their
compiler in a non-conforming mode, just so that I can use some features
that I'm doing perfectly well without, thank you.

Now, could you please explain in what way you think C99 *is* portable,
given that practically no conforming C99 compilers exist?

--
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
Apr 4 '08 #12
Richard Heathfield wrote, On 04/04/08 21:23:

<snip>
Now, could you please explain in what way you think C99 *is* portable,
given that practically no conforming C99 compilers exist?
You can put a copy of the C99 standard on a memory card or USB stick etc
and carry it around with you very easily ;-)
--
Flash Gordon
Apr 4 '08 #13
Richard Heathfield wrote:
And I am *not* going to ask my users to invoke their
compiler in a non-conforming mode, just so that I can use some features
that I'm doing perfectly well without, thank you.
Since Mr Heathfield insists using gcc in -ansic and NOT -std=c99 mode
gcc will NOT compile c99.

THEN it follows that c99 is *nowhere implemented* etc.

The key here is:
so that I can use some features
that I'm doing perfectly well without,
He doesn't like c99.

For whatever reasons I do not care. But he should stop praising
"standard C" because what he is using is not standard C.

I will not answer this polemic since it has been recooked too
many times to have any taste any more.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Apr 4 '08 #14
jacob navia said:

<snip>
But he should stop praising
"standard C" because what he is using is not standard C.
But who *is* using standard C? More specifically, what proportion of C
programmers use C99-conforming implementations? Well, that's an unfair
question because I don't suppose you know any better than I do - but it is
perfectly clear that the percentage is very, very small indeed.

<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
Apr 4 '08 #15

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

Similar topics

20
by: skoco | last post by:
Hello! Do you know when will be the new standard for c++ approved? And WHAT will be inside? Hope there will be some thread and synchro classes, text and XML parsing, new containers and other new...
88
by: Matt | last post by:
Hi folks. Can you help with some questions? I gather that some types supported by g++ are nonstandard but have been proposed as standards. Are the long long and unsigned long long types still...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
10
by: BilfFord X | last post by:
I'd like to elicit comment from the moderator of the full-contact version of this forum. In particular, I would like to know his philosophy on the language and I means by which I can identify him....
56
by: Chris Hills | last post by:
Hi, It came up in a standards panel meeting the other day that "all c or C++ programmers" have a copy of ISO C and/or C++ ... I challenged this and said most don't (outside those working on...
27
by: Simon Biber | last post by:
The following Example 3 is given in the 1999 C standard for the function fscanf: I have tested several implementations and none of them get the last case right. In no case does fscanf return 0...
20
by: Chor Lit | last post by:
Hi, I asked Bjarne Stroustrup about the idea of adding colour standard for C++, and he said that it is very difficult for compiler vendors to change their IDE. But do you think it is possible ? ...
3
by: Michael Ekstrand | last post by:
I'm looking for a standard (or standard-ish) way to determine the maximum value representable by a size_t. I can't seem to find anything officially standard - cstddef doesn't seem to define such a...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.