473,805 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1291
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.co mwrites:
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);in t main(void){unsi gned long b[]
={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,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)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}
Apr 3 '08 #3
jacob navia <ja***@nospam.c omwrites:
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_Keit h) <ks***@mib.or g>
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.c omwrites:
>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.c omwrites:
Keith Thompson wrote:
>jacob navia <ja***@nospam.c omwrites:
>>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_Keit h) <ks***@mib.or g>
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********@gma il.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_Keit h) <ks***@mib.or g>
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

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

Similar topics

20
2276
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 things. God save me from coding in boring & slow & no pointers java!! p.s.: how much time usually needs the compiler vendors to implement new standards? p.s.2: anybody knows which compiler supports export keyword? Thanks to you all.
88
6038
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 under consideration for the ANSI C and C++ standards? Are they likely to be accepted into the standards? Which compilers support those types, and which do not?
32
30512
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 namespace in C. Of course, namespace doesn't eliminate name polution, but it helps more than just to put some prefix before a function name. Is it because adding namespace will make C more complex or some other reasons?
10
1535
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. Cordially, bfx
56
3142
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 the standards). Well, do most of you have a copy of the relevant ISO language standard of your own or is there one on your desk at work?
27
2837
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 indicating failure to match "100ergs of energy" with "%f". The actual behaviour varies. Some will match '100', leaving the 'e' unread:
20
3177
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 ? Note that the proposed colour standard is not just merely to ease the eye only as what presently is in C++ compilers, but to aid in syntax disambiguation and other advantages. Here are a few advantages that I can think of:
3
7807
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 thing, nor does climits. Applying grep to my /usr/include reveals an stdint.h header which defines a SIZE_MAX, some further research indicates that this is a C99 standard header but not standard for either C89 or standard C++. My primary...
126
6760
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: http://www.cse.wustl.edu/~schmidt/ACE.html the same way that the STL (and subsequently BOOST) have been subsumed? Since it already runs on zillions of platforms, they have obviously worked most of the kinks out of the generalized threading and processes idea (along with many...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.