473,840 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C99 portability challenge

Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.

I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.

The program is designed to produce the sum of the natural
integers up to a user provider argument. For instance
the call
sum 55
should produce
The sum of the first 55 integers is 1540.

-----------------------------------------------cut here
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int sum=0;

if (argc < 2) {
printf("Usage: sum <number>\n");
return 1;
}

int top = atoi(argv[1]);

if (top <= 0)
return 0;
if (top 100) {
printf("Maximum value 100. Enter a lower value\n");
return 1;
}

int vla[top];

for (int i=0; i<top;i++) {
vla[i] = i+1;
}

for (int j = 0; j<top;j++) {
sum += vla[j];
}

printf("The sum of the first %d integers is %d\n",top,sum);
return 0;
}
------------------------------------------------cut here

I have already successfully compiled this program under

(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc

I do not have any other type of system available. Please
if you have a system not listed above try to compile
this.

Thanks in advance.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Aug 26 '08 #1
80 3085
Jensen Somers wrote:
Hello,

jacob navia wrote:

<snip>
>>
I have already successfully compiled this program under

(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc

I do not have any other type of system available. Please
if you have a system not listed above try to compile
this.

Thanks in advance.

The application fails to compile on Windows using Visual Studio 2005 and
Visual Studio 2008.

When compiling using C mode (/TC) the application fails to compile due
to the declaration of 'int top', 'int i' and any other variable
declaration that is not at the beginning of the function. I believe this
is default C90 behavior.

When compiling using C++ mode (/TP) the application fails to compile due
to the declaration of 'int vla[top]' because 'top' is not a constant
expression and it is unable to create an array of constant size 0.

- Jensen
You can use Intel compiler within Visual studio, so C99 is supported
under windows. lcc-win also supports C99, and gcc (mingw) is used there
too, so the windows systems are sell served.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Aug 26 '08 #2
jacob navia wrote:
Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.

I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.

The program is designed to produce the sum of the natural
integers up to a user provider argument. For instance
the call
sum 55
should produce
The sum of the first 55 integers is 1540.

-----------------------------------------------cut here
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int sum=0;

if (argc < 2) {
printf("Usage: sum <number>\n");
return 1;
}

int top = atoi(argv[1]);

if (top <= 0)
return 0;
if (top 100) {
printf("Maximum value 100. Enter a lower value\n");
return 1;
}

int vla[top];

for (int i=0; i<top;i++) {
vla[i] = i+1;
}

for (int j = 0; j<top;j++) {
sum += vla[j];
}

printf("The sum of the first %d integers is %d\n",top,sum);
return 0;
}
------------------------------------------------cut here

I have already successfully compiled this program under

(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc
(4): FreeBSD using gcc -std=c99
--
Pietro Cerutti
Aug 26 '08 #3
On Aug 26, 4:07*am, jacob navia <ja...@nospam.c omwrote:
Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.

I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.

The program is designed to produce the sum of the natural
integers up to a user provider argument. For instance
the call
* * * * sum 55
should produce
The sum of the first 55 integers is 1540.

-----------------------------------------------cut here
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
* * * * int sum=0;

* * * * if (argc < 2) {
* * * * * * * * printf("Usage: sum <number>\n");
* * * * * * * * return 1;
* * * * }

* * * * int top = atoi(argv[1]);

* * * * if (top <= 0)
* * * * * * * * return 0;
* * * * if (top 100) {
* * * * * * * * printf("Maximum value 100. Enter a lower value\n");
* * * * * * * * return 1;
* * * * }

* * * * int vla[top];

* * * * for (int i=0; i<top;i++) {
* * * * * * * * vla[i] = i+1;
* * * * }

* * * * for (int j = 0; j<top;j++) {
* * * * * * * * sum += vla[j];
* * * * }

* * * * printf("The sum of the first %d integers is %d\n",top,sum);
* * * * return 0;}

------------------------------------------------cut here

I have already successfully compiled this program under

(1): windows using lcc-win.
(2): linux using gcc -std=c99
(3): AIX using xlc

I do not have any other type of system available. Please
if you have a system not listed above try to compile
this.

Thanks in advance.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehtt p://www.cs.virginia .edu/~lcc-win32
I don't have access to my FreeBSD and Linux boxes,
but here I have an old version of gcc:

-----8<----------8<----------8<----------8<-----
[XXXXXXXX@XXXXXX X ~$] env LC_ALL=C gcc --version
gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

[XXXXXXXX@XXXXXX X ~$] gcc -Wall -Wextra -Wshadow -pedantic -std=c99 -o
sum.exe sum.c
[XXXXXXXX@XXXXXX X ~$] gcc
gcc: no hay ficheros de entrada
-----8<----------8<----------8<----------8<-----

At night I will try with more compilers, I think that
gcc version 3.X it's a little bit old, I mean gcc 4.X
would have more strict warnings with the -pedantic
flags.

Regards,
DMW
Aug 26 '08 #4
On Tue, 26 Aug 2008 10:28:14 +0200, Jensen Somers wrote:
The application fails to compile on Windows using Visual Studio 2005 and
Visual Studio 2008.

When compiling using C mode (/TC) the application fails to compile due
to the declaration of 'int top', 'int i' and any other variable
declaration that is not at the beginning of the function. I believe this
is default C90 behavior.
He did mentioned C99 in the subject line, which doesn't require that all
variable declarations should be restricted to the beginning of a function.

Why not try to compile the code with a decent, standard compliant
compiler?
Rui Maciel
Aug 26 '08 #5
Rui Maciel said:
On Tue, 26 Aug 2008 10:28:14 +0200, Jensen Somers wrote:
>The application fails to compile on Windows using Visual Studio 2005 and
Visual Studio 2008.

When compiling using C mode (/TC) the application fails to compile due
to the declaration of 'int top', 'int i' and any other variable
declaration that is not at the beginning of the function. I believe this
is default C90 behavior.

He did mentioned C99 in the subject line, which doesn't require that all
variable declarations should be restricted to the beginning of a
function.

Why not try to compile the code with a decent, standard compliant
compiler?
So you seem to be saying that C99 programs are portable to conforming C99
compilers, is that right? What do you want us to do - hold the front page?

As I understand it, the point (such as it is) of Jacob Navia's challenge is
to establish whether a rather naive little program that makes undemanding
use of a VLA is portable across a variety of not-quite-C99
implementations .

If he had written the program slightly differently:

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int rc = EXIT_SUCCESS;

unsigned long n = argc 1 ? strtoul(argv[1], NULL, 10) : 0;
if(n 0 && n <= 100)
{
printf("The sum of the first %lu integers is %lu\n",
n, n * (n + 1) / 2);
}
else
{
puts("Please use an argument in the range 1 to 100 inclusive.");
rc = EXIT_FAILURE;
}
return rc;
}

then it would have been portable to *all* conforming hosted
implementations , C90 as well as C99 (as well as being faster and shorter
than his original). But that would have been beside his point. He has
purposefully introduced non-portable features into the code with the
intent of demonstrating that they aren't really as non-portable as all
that, really. How far he has succeeded is rather questionable, since his
code steps around many C99 conformance issues.

(Frankly, I'd rather use the shorter, faster, more portable version, but
YMMV.)

--
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 26 '08 #6
jacob navia <ja***@nospam.c omwrites:
Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.

I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.
[snip]

See my response in comp.std.c.

--
Keith Thompson (The_Other_Keit h) 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"
Aug 26 '08 #7
On Tue, 26 Aug 2008 10:28:14 +0200, Jensen Somers wrote:
The application fails to compile on Windows using Visual Studio 2005 and
Visual Studio 2008.

When compiling using C mode (/TC) the application fails to compile due
to the declaration of 'int top', 'int i' and any other variable
declaration that is not at the beginning of the function. I believe this
is default C90 behavior.
He did mentioned C99 in the subject line, which doesn't require that all
variable declarations should be restricted to the beginning of a function.

Why not try to compile the code with a decent, standard compliant
compiler?
Rui Maciel
Aug 26 '08 #8
On Tue, 26 Aug 2008 16:21:58 +0000, Richard Heathfield wrote:
So you seem to be saying that C99 programs are portable to conforming
C99 compilers, is that right? What do you want us to do - hold the front
page?
Not quite. I pointed out that, as it is stated in the subject, the
standard being considered was C99, which, among other features, allows
variables to be defined in arbitrary places inside blocks.

Knowing that, I believe you can agree that all that sarcasm was uncalled
for.

As I understand it, the point (such as it is) of Jacob Navia's challenge
is to establish whether a rather naive little program that makes
undemanding use of a VLA is portable across a variety of not-quite-C99
implementations .

If he had written the program slightly differently:
<snip />
then it would have been portable to *all* conforming hosted
implementations , C90 as well as C99 (as well as being faster and shorter
than his original). But that would have been beside his point.
If the intended purpose of Jacob Navia's challenge is to test C99's
portability then I don't understand the need to leave out any C99
feature. Wouldn't that defeat the purpose of this challenge?

Moreover, I do believe that it is more interesting and productive to test
C99's implementations (and also partial implementations ) instead of C90.

He has
purposefully introduced non-portable features into the code with the
intent of demonstrating that they aren't really as non-portable as all
that, really.
Do you happen to mean "C99 features" instead of "non-portable features"?
Rui Maciel
Aug 26 '08 #9
On Aug 26, 11:07 am, jacob navia <ja...@nospam.c omwrote:
Several people in this group argue that standard C
is not portable since there are no compilers for it, etc.
They are all fools (note: I'm not insulting anyone, since nobody has
claimed _that_)
Standard C is not "portable" or "not portable". It's a language
standard.
What several people in this group say is that there isn't a C99
implementation yet.
I propose this program in Standard C, that I have compiled
in several OSes to test if this is actually true. My
basic idea is to see which systems do not have a compiler that
supports standard C.
Tests are meaningless.
Aug 26 '08 #10

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

Similar topics

7
1624
by: fabio de francesco | last post by:
Hi, I'm not a professional programmer, but I've been writing C/C++ and Ada programs for a few years on GNU/Linux without ever concerning on standards and portability to other OSs. I've always noted that when I write code I must use lots of platform specific system calls (POSIX and X/OPEN). Often I found myself using threads and concurrent processes with some sort of IPC. Some time I need some socket API. When I just want to open a...
8
1719
by: Frank Buss | last post by:
A new challenge: http://www.frank-buss.de/marsrescue/index.html Have fun! Now you can win real prices. -- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
21
1932
by: asm | last post by:
Hi All, Like typdef, does C have further support for portability? Thanks, ASM
93
3696
by: roman ziak | last post by:
I just read couple articles on this group and it keeps amazing me how the portability is used as strong argument for language cleanliness. In my opinion, porting the program (so you just take the source code and recompile) is a myth started 20-30 years ago when world consisted of UNIX systems. Well, world does not consist of UNIX systems anymore, but there are 100s of different systems running in cell-phones, DVD players, game consoles...
0
1217
by: Richard Jones | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from scratch either as an individual or in a team. Entries must be developed in Python, during the challenge, and must incorporate some theme chosen at the start of the challenge. REGISTRATION IS NOT YET OPEN --
0
1238
by: richard | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from scratch either as an individual or in a team. Entries must be developed in Python, during the challenge, and must incorporate some theme chosen at the start of the challenge. REGISTRATION IS NOW OPEN --
93
4027
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code so that it will compile in all old and broken compilers, preferably in such a fashion that it can be moved with no effort from the embedded system in the coffe machine to the 64 bit processor in your desktop.
239
10363
by: Eigenvector | last post by:
My question is more generic, but it involves what I consider ANSI standard C and portability. I happen to be a system admin for multiple platforms and as such a lot of the applications that my users request are a part of the OpenSource community. Many if not most of those applications strongly require the presence of the GNU compiling suite to work properly. My assumption is that this is due to the author/s creating the applications...
18
409
by: jacob navia | last post by:
One of the holy cows here is this "portability" stuff. In practice, portability means: 1) Use the least common denominator of all the supported systems. 2) Between usability / good user experience and portability always choose portability since this minimizes programming effort
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10656
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
9434
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...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
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...
1
4495
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
3
3136
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.