On gcc, which version of C standard has the most compliant: -c89, -ansi
or c99? For more portable C code, which options should be applied to
compilation?
Can the following options guarantee the most portable C code for
different environment?
gcc -ansi -pedantic -Wall test.c
--
lovecreatesbeau ty 28 2712
Le 15-06-2006, lovecreatesbeau ty <lo************ ***@gmail.com> a écrit*: On gcc, which version of C standard has the most compliant: -c89, -ansi or c99? For more portable C code, which options should be applied to compilation?
Can the following options guarantee the most portable C code for different environment?
gcc -ansi -pedantic -Wall test.c
Can't you read the documentation of GCC ?
To compile c89 code, the option is -std=c89.
Support of c99 is not universal today, so, when looking at
'portability', you could restrict yourself to c89.
Other options are there to warn you when you compile some code
that gcc find suspect.
Marc Boyer
lovecreatesbeau ty wrote:
.... snip ... Can the following options guarantee the most portable C code for different environment?
gcc -ansi -pedantic -Wall test.c
Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal"
--
Chuck F (cb********@yah oo.com) (cb********@mai neline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE maineline address!
Marc Boyer wrote: Can't you read the documentation of GCC ? To compile c89 code, the option is -std=c89. Support of c99 is not universal today, so, when looking at 'portability', you could restrict yourself to c89. Other options are there to warn you when you compile some code that gcc find suspect.
Thank you. But there are total 8933 lines in gcc manual document in
Debian Linux 3.1. Your expertise suggestion can just point out the
right selection from among nearly ten thousand lines of information.
CBFalconer wrote: Can the following options guarantee the most portable C code for different environment? gcc -ansi -pedantic -Wall test.c Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal"
Thank CBFalconer for the kind help.
lovecreatesbeau ty
CBFalconer wrote: lovecreatesbeau ty wrote: ... snip ... Can the following options guarantee the most portable C code for different environment?
gcc -ansi -pedantic -Wall test.c
Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal"
I dunno if that includes shadows but throw in -Wshadow as well if it
doesn't.
Tom to********@gmai l.com wrote: CBFalconer wrote: Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal" I dunno if that includes shadows but throw in -Wshadow as well if it doesn't.
I check gcc manual again and find that -Wall doesn't cover -Wshadow.
I'm sorry if I misunderstood you.
lovecreatesbeau ty
lovecreatesbeau ty wrote: to********@gmai l.com wrote: CBFalconer wrote: Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal" I dunno if that includes shadows but throw in -Wshadow as well if it doesn't.
I check gcc manual again and find that -Wall doesn't cover -Wshadow. I'm sorry if I misunderstood you.
Then add it. -Wshadow isn't for portability but a lot of beginners
seem to make that mistake, e.g.
int x = 5;
while (somethingelse != 0) {
int x;
for (x = 0; x < 17; x++) { ... }
}
printf("Why is %d==5 it should be 17!!!???\n", x);
Clearly that's a bit contrived but when you use variables like i, j, x,
y, z as loop counters it's trivial to re-use them in nested blocks.
For my code I typically use
-Wall -Wsign-compare -W -Wshadow -Wno-unused-parameter
With at least -O2 or -O3. Turning on optimization is required for
several warnings to fully work.
so if you used
--std=c99 -pedantic -O2 -Wall -Wsign-compare -W -Wshadow
-Wno-unused-parameter
You're likely to catch most common programming mistakes as well as
standards violations. The trick is to not only use these flags but
then ADDRESS the diagnostics raised. Too many people use -Wall then
ignore all the output because "my code is right" syndrome kicks in.
Tom
On 2006-06-15, to********@gmai l.com <to********@gma il.com> wrote: CBFalconer wrote: lovecreatesbeau ty wrote: > ... snip ... > Can the following options guarantee the most portable C code for > different environment? > > gcc -ansi -pedantic -Wall test.c
Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal"
I dunno if that includes shadows but throw in -Wshadow as well if it doesn't.
This from Richard Heathfield:
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
-Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes
-Wmissing-declarations -Winline -Wundef -Wnested-externs -Wcast-qual
-Wshadow -Wconversion -Wwrite-strings -Wno-conversion
(You'll have to un-linewrap that a fair bit).
--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head.
lovecreatesbeau ty wrote: On gcc, which version of C standard has the most compliant: -c89, -ansi or c99? For more portable C code, which options should be applied to compilation?
Can the following options guarantee the most portable C code for different environment?
gcc -ansi -pedantic -Wall test.c
No, because "standard-compliant" does not necessarily imply "portable."
Code that assumes a particular endianness or uses bitfields to model
architecture-specific structures or relies on a platform-specific API
may compile cleanly with the above command, yet still not be portable
(or at least not maximally so).
Don't get me wrong, it's good practice, and it will catch some obvious
errors that may affect portability, but it won't guarantee that the
code is portable. to********@gmai l.com wrote: CBFalconer wrote: lovecreatesbeau ty wrote: ... snip ... Can the following options guarantee the most portable C code for different environment?
gcc -ansi -pedantic -Wall test.c
Try "gcc -W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal"
I dunno if that includes shadows but throw in -Wshadow as well if it doesn't.
It doesn't, and adding it is a bad idea. There are times when you
deliberately want to hide an outer scoped identifier, and shadowing
it with a local one is the ideal method.
....
int important; /* critical to the rest of the system */
....
int mybiglongfuncti onNOTusingimpor tant(params) {
....
int local;
int impossible;
...
important = whatever; /* absent minded typo for impossible */
...
}
The above will be perfectly legal coding, but buggy. The bug will
cause total implosion elsewhere. By simply relabelling impossible
as important we prevent such from ever occuring. Shadow good, bug
bad.
--
Chuck F (cb********@yah oo.com) (cb********@mai neline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE maineline address! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: googleboy |
last post by:
Hi there.
I am writing a little app tha tI would like to make cross-platform
(debian, RH, Fedora, Solaris, AIX, etc)
Originally I decided to check what uname returned, as I didn't think it
mattered beyond the detail of Linux or SunOS etc.
Recently I have learned that FC3 breaks my script, so I need to be
able to determine not simply "Linux" but to know exactly what unix the
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: Jeff Rodriguez |
last post by:
If main is prototyped as:
int main(int argc, char *argv);
You will end up with a bunch of arguments in *argv, and the number in argc. Now
what I want to do is emulate that same action on a string. Say for example I have:
char *command = "./blah --arg1 --arg2 123 -x --arg2=w00t"
How do I acheive the same effect as in main()?
|
by: rahul8143 |
last post by:
hello,
what is difference between sizeof("abcd") and strlen("abcd")? why
both functions gives different output when applied to same string
"abcd".
I tried following example for that.
#include <stdio.h>
#include <string.h>
void main()
{
char *str1="abcd";
|
by: Frederick Gotham |
last post by:
If we look at a programming language such as C++: When an updated Standard
comes out, everyone adopts it and abandons the previous one.
It seems though that things aren't so clear-cut in the C community. It
would seem that C99 is the most up-to-date Standard, but far more people
seem to be working off the C89 Standard.
Could someone please explain to me why this is so?
--
| |
by: LuisC |
last post by:
What is better for holding small numbers in a program?
I know that char uses less memory, but, with 32 or 64 bits systems,
there are advantages (such as processing time) in using int instead of
char for small numbers?
Luis
|
by: albert.neu |
last post by:
Hello!
What is a good compiler to use? (for MS Windows, for Linux)
Any recommendations??
What's the point of having a C99 standard, if different compilers
still produce differing results?
The main reason for a standard, is (in my opinion) portabilty and
|
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...
|
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,...
|
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...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |