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

Compile Errors

I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?

When I attempt to make or compile my C code, the compiler complains
about the syntax of the function prototypes, even though the syntax is
correct.

Example syntax:

void function_name(void);

If the issue is not with the compiler, what else could be causing the
compile error?

Thanks!

Feb 11 '06 #1
8 1660
In article <11**********************@f14g2000cwb.googlegroups .com>,
Technoid <da****@criterialabs.com> wrote:
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?
Yes, definitely. K&R's prototypes are quite different.

When I attempt to make or compile my C code, the compiler complains
about the syntax of the function prototypes, even though the syntax is
correct. Example syntax: void function_name(void);
void is not part of K&R C.

If the issue is not with the compiler, what else could be causing the
compile error?


That you are trying to use features that did not exist when that
compiler was created.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Feb 11 '06 #2
>In article <11**********************@f14g2000cwb.googlegroups .com>,
Technoid <da****@criterialabs.com> wrote:
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?
In article <ds**********@canopus.cc.umanitoba.ca>
Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
Yes, definitely. K&R's prototypes are quite different.


More specifically, K&R C lacks prototypes entirely.
void function_name(void);


void is not part of K&R C.


It was, however, a very common extension.

Prototypes (and other things that are liable to crop up here) have
been standard for over 15 years now. The OP did say "legacy test
platform", but sometimes legacy is too painful even to contemplate.
:-) Still, here are some tricks.

The "void problem" can be worked-around easily:

#define void int

The next step might be to revert to a technique commonly used many
years ago, back when prototypes were new:

#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif

double somefunc P((char *, double *));

Now the prototype portion of a declaration vanishes when needed
(not __STDC__) but remains when possible (__STDC__). (One might
tweak the #ifdef, since some non-standard compilers still had
prototype support, back then.)

You can also handle "const" by #defining it away:

#define const /*nothing*/

and likewise for "volatile". A few tricks like this, plus a modest
amount of source-code discipline, can produce code that compiles
correctly with a K&R compiler, yet still uses prototypes on modern
systems.
--
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: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Feb 11 '06 #3
"Technoid" <da****@criterialabs.com> writes:
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?

When I attempt to make or compile my C code, the compiler complains
about the syntax of the function prototypes, even though the syntax is
correct.

Example syntax:

void function_name(void);

If the issue is not with the compiler, what else could be causing the
compile error?


K&R C didn't have prototypes. It also didn't have the "void" keyword.

K&R defines the K&R version of the language. More specifically,
Kernighan & Ritchie, _The C Programming Language_, First Edition (the
second edition covers the ANSI/ISO standard, C89/C90). Copies should
still be available, at least used.

There's a tool called "ansi2knr" that attempts to translate ANSI C
code to K&R-compatible code (removing prototypes, etc.). It probably
doesn't do a perfect job.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 11 '06 #4
Keith Thompson <ks***@mib.org> writes:
"Technoid" <da****@criterialabs.com> writes:
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?

When I attempt to make or compile my C code, the compiler complains
about the syntax of the function prototypes, even though the syntax is
correct.

Example syntax:

void function_name(void);

If the issue is not with the compiler, what else could be causing the
compile error?
K&R C didn't have prototypes. It also didn't have the "void" keyword.

K&R defines the K&R version of the language. More specifically,
Kernighan & Ritchie, _The C Programming Language_, First Edition (the
second edition covers the ANSI/ISO standard, C89/C90). Copies should


One more thing: K&R1 was published shortly before the "enum" keyword
was added to the language, but most pre-ANSI compilers support "enum".
Chris says "void" was a common extension; I didn't know that, but I'll
take his word for it. But the only really relevant question is what's
supported by the particular antediluvian compiler you're being forced
to support.

(You should seriously consider the possibility that this whole
exercise is a waste of time. I don't know of any significant systems
that don't have at least a C89/C90 compiler. If you have an old
system with a K&R compiler, you can probably use it to bootstrap gcc,
though probably not the latest version.)
There's a tool called "ansi2knr" that attempts to translate ANSI C
code to K&R-compatible code (removing prototypes, etc.). It probably
doesn't do a perfect job.


And because of this, you might need to tweak your ANSI-compatible code
in some minor ways so that (a) ansi2knr doesn't choke on it, and (b)
your legacy compiler doesn't choke on the output of ansi2nkr. Such
tweaks are likely, but not certain, to be less intrusive than using
#ifdefs to make all your prototypes and "void"s conditional on
__STDC__.

Argument promotion, I think, is something that ansi2nkr doesn't handle
very well. The K&R code:

int foo(c)
char c;
{ /* ... */ }

isn't actually equivalent to this:

int foo(char c)
{ /* ... */ }

it's closer to this:

int foo(int c)
{ /* ... */ }

This kind of thing can cause subtle errors if you're not *very*
careful.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 11 '06 #5

"Technoid" <da****@criterialabs.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?


I think others convered the function prototype question. So the question is
how early a version of K&R?

A) Early K&R twenty-five keywords:
#define #include auto break case char continue
default do double else entry extern float for
goto if int register return sizeof static
struct switch while

B) Early K&R, ten operators written in reverse when compared to modern C:
=>> =>> =+ =- =* =/ =% =& =^ =|

C) Other operators and structural elements:
<< ++ -- -> && || <= >= == != ; { } , : = ( )

[ ] . & ! ~ - + * / % < > ^ | ?

Rod Pemberton

Feb 11 '06 #6
"Rod Pemberton" <do*********@sorry.bitbucket.cmm> writes:
"Technoid" <da****@criterialabs.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?

I think others convered the function prototype question. So the question is
how early a version of K&R?

A) Early K&R twenty-five keywords:
#define #include auto break case char continue
default do double else entry extern float for
goto if int register return sizeof static
struct switch while


I don't think #define and #include were ever considered keywords.
B) Early K&R, ten operators written in reverse when compared to modern C:
=>> =>> =+ =- =* =/ =% =& =^ =|


Early versions of C used "=-" rather than "-=". Since K&R1 (the book)
uses the modern "-=" form, I'd refer to such versions of the language
as pre-K&R. (I think the book mentions the older forms in passing.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 11 '06 #7
On 11 Feb 2006 09:55:05 -0800, in comp.lang.c , "Technoid"
<da****@criterialabs.com> wrote:
I'm working on a legacy test platform with a compiler that expects K&R
style C (as opposed to ANSI). How does this affect the required syntax
for my code? Would it affect syntax for function prototypes?
Very much so, since K&R C doesn't allow prototypes AFAIR. You can have
declarations tho.
When I attempt to make or compile my C code, the compiler complains
about the syntax of the function prototypes, even though the syntax is
correct.

Example syntax:

void function_name(void);


This isn't valid pre-ANSI C. You need to remove the void, and any
other parameters, from the prototype to turn it into a plain old
declaration.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 12 '06 #8
On 2006-02-11, Chris Torek <no****@torek.net> wrote:
A few tricks like this, plus a modest amount of source-code
discipline, can produce code that compiles correctly with a K&R
compiler, yet still uses prototypes on modern systems.


Also, watch out for narrow types - you will of course have to code using
"old-style" function definitions [macros to conditionally use old or new
style aren't really worth it]
int foo(x,y) char x; float y; {
...
}

needs the prototype

int foo P((int x, double y))
Feb 13 '06 #9

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

Similar topics

1
by: Ravi Chaudhary | last post by:
Hi, We are using VS.Net 2003 and coding in VB.net. The solution has 38 projects; most of the projects in the solution reference other projects (without any circular references) and all the...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
7
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance....
1
by: Ray Wampler | last post by:
According to the information on the Microsoft web site, code written in VB.NET 2002 can simply be recompiled using VS.NET 2003. However, I have found that code which compiles cleanly in VS.Net...
1
by: Ravi Chaudhary | last post by:
Hi, We are using VS.Net 2003 and coding in VB.net. The solution has 38 projects; most of the projects in the solution reference other projects (without any circular references) and all the...
0
by: Jérôme Le Bougeant | last post by:
Hello (and sorry for my English), I downloaded the VideoCapture module on the http://videocapture.sourceforge.net/ site. I tested it with a webcam and that functions. Now I want to...
22
by: Tomás Ó hÉilidhe | last post by:
I've been developing a C89 microcontroller application for a while now and I've been testing its compilation using gcc. I've gotten zero errors and zero warnings with gcc, but now that I've moved...
9
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
2
by: Andrus | last post by:
I need compile in-memory assembly which references to other in-memory assembly. Compiling second assembly fails with error Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,...
1
by: =?Utf-8?B?SG93YXJkIFBpbnNsZXk=?= | last post by:
I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at "Converting a Web Site Project to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
0
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,...
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
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.