Segmentation Fault....

F

Flash Gordon

jacob navia wrote, On 10/04/07 19:09:
Richard Heathfield a écrit :
BRAVO Heathfield:
According to http://dn.codegear.com/article/20841
Antique Software: Turbo C version 2.01
Ship date: 11-May-1989

Still in use.
The official name is
Borland C++ 5.02. You have surely tweaked the compiler to
put it in some configuration that doesn't accept //

I have compiled with that compiler and it will accept //
in C mode.

Not in conforming C mode.
It accepts those comments since at least
1995 or even earlier. In any case, since 1995
they are accepted in C mode. This is just a lie.

Not in conforming C mode.
Gcc accepts // comments in C mode unles you force it not to.
This is a lie too.

Not when told to conform to the only standard it claims to fully conform to.
Conforming to WHAT?

You are being disingenuous at best, since you know that all of those
compilers only fully conform to one standard.
Obviously conforming to C89. Many compilers have a flag that
makes them conforming to C89, even lcc-win32 has one. But this
is just another lie Hethfield.

No, it is the absolute truth.
IBM does (In the power pc version of their compiler for instance)
gcc does
and many other compilers have adopted C99.

gcc has a mode that fully conforms to C89 and a mode that according to
its developers does not fully conform to C99. However, you know this.
But if you want to live in the past, or in some world that
stopped spinning in 1989 you are welcome.

But do not pretend that would be standard C.

You have mentioned one compiler that I think has a full C99 mode (maybe
two if you have finished implementing yours, including the library). All
the others, including all the ones that a lot of us use, either do not
fully support C99 or do not support it at all.

Personally I would very much like to move to C99 since there are a few
things I would like to use, however I have to allow for compatibility
with MS compilers. Many others have good reasons for not being able to
use C99.
 
M

Malcolm McLean

jacob navia said:
Daniel Rudy a écrit :

This is nonsense.

// comments are standard C!!!
We don't have a standard any longer. I included some slash slash comments in
my code on the basis that if any extension was now standard, that one was,
only to find them break on an MPI compiler. It also uses Fortran 77.
 
D

Daniel Rudy

At about the time of 4/10/2007 8:22 AM, (e-mail address removed) stated the
following:
Thanks for the tip about scanf..can't believe it was a simple wrong
type......
I don't think C/C++ comments make much difference....

I wasn't the one who came up with the scanf issue, but the C++ style
comments prevented your code from compiling on my system.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
D

Daniel Rudy

At about the time of 4/10/2007 8:32 AM, jacob navia stated the following:
(e-mail address removed) a écrit :

// comments are standard C. Mr Rudy is completely wrong.

Really? Then why will the code not compile on gcc using -ansi -std=c89?


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
D

Daniel Rudy

At about the time of 4/10/2007 10:04 AM, jacob navia stated the following:
Richard Heathfield a écrit :
jacob navia said:

Charlton Wilbur a écrit :


N> Thanks for the tip about scanf..can't believe it was a simple
N> wrong type...... I don't think C/C++ comments make much
N> difference....

They do if you want help from this group, for two reasons.

First, // comments were only included in the C99 standard. While
they are technically standard, using them is more often than not a
sign of sloppy thinking about C and a lack of awareness of C
standards, which is likely to reflect poorly on the programmer and
irritate the most helpful people here (who care deeply about what is
standard and non-standard in C).
Look Mr, if you "care deeply about what is standard and non-standard"
please stop talking nonsense.

He's not talking nonsense. He makes good points, only one of which you
have left unsnipped.

The C standard 6.4.9: Comments

Except within a character constant, a string literal, or a comment,
the characters // introduce a comment [...]

Yes, you're right - C99 introduced // comments. Nobody is disputing
this.

The C99 standard is the current standard.

Nobody is disputing that either. It's just that almost nobody uses the
C99 Standard in daily life. It's still a C90 world.
Excuse me, I have yet to find a C compiler that does NOT accept
// comments.

Please show me *some* example for those...

gcc on Unix with these options:

gcc -W -Wall -pedantic -ansi -std=c89


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
I

Ian Collins

Daniel said:
At about the time of 4/10/2007 8:32 AM, jacob navia stated the following:



Really? Then why will the code not compile on gcc using -ansi -std=c89?
Because they are legal in the current standard, not the old one.
 
I

Ian Collins

Daniel said:
At about the time of 4/10/2007 10:04 AM, jacob navia stated the following:

gcc on Unix with these options:

gcc -W -Wall -pedantic -ansi -std=c89
So it doesn't accept them if you explicitly tell it not to. Wow, I'm
impressed.
 
D

Daniel Rudy

At about the time of 4/10/2007 8:31 AM, jacob navia stated the following:
Daniel Rudy a écrit :

This is nonsense.

// comments are standard C!!!

jacob

Then explain this:

strata:/home/dr2867/c/test 1031 $$$ ->more -N test1.c
1 #include <stdio.h>
2 #include <math.h>
3
4 //------------------------------------------------------
5 // Programming II - Coursework Assignment 1-4
6 // This program calculates the following :
7 // - Sum of numbers
8 // - Sum of numbers squared
9 //- Mean
10 // - Mean of numbers squared
11 // - Standard Deviation
12 //- Error in mean of a set of numbers
13 //------------------------------------------------------
14 // Note: This version differs in the previous version.
15 // 1.)Arrays are used to store and be read
16 // 2.)Two functions are introduced vsum, vsum2
17 // 3.)Array refuses to accept more values
18 //------------------------------------------------------
19
20 //Functions


Using c89 standard:

strata:/home/dr2867/c/test 1032 $$$ ->gcc -W -Wall -pedantic -ansi
-std=c89 -o test1 test1.c
test1.c:4: error: syntax error before '/' token
strata:/home/dr2867/c/test 1033 $$$ ->


Using C90 standard:

strata:/home/dr2867/c/test 1034 $$$ ->gcc -W -Wall -pedantic
-std=iso9899:199409 -o test1 test1.c
test1.c:4: error: syntax error before '/' token
strata:/home/dr2867/c/test 1035 $$$ ->


Looks pretty conclusive to me. Just because you are using a standard
that may or may not be supported by any one compiler, doesn't mean that
the rest of us have to. I perfer c89 for all my stuff, and then I use
C90 when I need to use long long or unsigned long long.


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
D

Daniel Rudy

At about the time of 4/10/2007 2:19 PM, Ian Collins stated the following:
So it doesn't accept them if you explicitly tell it not to. Wow, I'm
impressed.

Not you too.

I always use -std=c89 -ansi options when I compile my code. Sometimes I
use -std=iso9899:199409 for C90 standard when I need it. I don't need
or have the desire to code to C99, especially when it's only partly
implemented.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
I

Ian Collins

Daniel said:
At about the time of 4/10/2007 8:31 AM, jacob navia stated the following:


Then explain this:

strata:/home/dr2867/c/test 1031 $$$ ->more -N test1.c
1 #include <stdio.h>
2 #include <math.h>

cc y.c
"y.c", line 1: syntax error before or at: 1
"y.c", line 1: invalid source character: '#'
"y.c", line 1: warning: old-style declaration or incorrect type for: include
"y.c", line 1: warning: old-style declaration or incorrect type for: stdio
"y.c", line 1: warning: old-style declaration or incorrect type for: h
 
A

Army1987

Looks pretty conclusive to me. Just because you are using a standard
that may or may not be supported by any one compiler, doesn't mean that
the rest of us have to. I perfer c89 for all my stuff, and then I use
C90 when I need to use long long or unsigned long long.

You meant C99. C90 is practically the same as C89.
 
D

Daniel Rudy

At about the time of 4/10/2007 2:30 PM, Army1987 stated the following:
You meant C99. C90 is practically the same as C89.

No, I meant c89. I explicitly use -ansi -std=c89 for most of my C code.



--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
J

jacob navia

Ian Collins a écrit :
So it doesn't accept them if you explicitly tell it not to. Wow, I'm
impressed.

Me too. It is impressing how apparently intelligent people
will use completely moronic arguments:

:)

But this is hopeless.
 
J

jacob navia

Daniel Rudy a écrit :
At about the time of 4/10/2007 8:31 AM, jacob navia stated the following:



Then explain this:

strata:/home/dr2867/c/test 1031 $$$ ->more -N test1.c
1 #include <stdio.h>
2 #include <math.h>
3
4 //------------------------------------------------------
5 // Programming II - Coursework Assignment 1-4
6 // This program calculates the following :
7 // - Sum of numbers
8 // - Sum of numbers squared
9 //- Mean
10 // - Mean of numbers squared
11 // - Standard Deviation
12 //- Error in mean of a set of numbers
13 //------------------------------------------------------
14 // Note: This version differs in the previous version.
15 // 1.)Arrays are used to store and be read
16 // 2.)Two functions are introduced vsum, vsum2
17 // 3.)Array refuses to accept more values
18 //------------------------------------------------------
19
20 //Functions


Using c89 standard:

strata:/home/dr2867/c/test 1032 $$$ ->gcc -W -Wall -pedantic -ansi
-std=c89 -o test1 test1.c
test1.c:4: error: syntax error before '/' token
strata:/home/dr2867/c/test 1033 $$$ ->


Using C90 standard:

strata:/home/dr2867/c/test 1034 $$$ ->gcc -W -Wall -pedantic
-std=iso9899:199409 -o test1 test1.c
test1.c:4: error: syntax error before '/' token
strata:/home/dr2867/c/test 1035 $$$ ->


Looks pretty conclusive to me.

Yes. If you tell gcc not to use the current standard but some other old
one it will not accept standard syntax.

WOW, how clever you are.
> Just because you are using a standard
that may or may not be supported by any one compiler, doesn't mean that
the rest of us have to.

I am speaking about standard C. Nobody forces you to use anything
and if you do not like standrad C I do not care. But I do not want
to allow that you pass YOUR preferences as standard C. They are not.


I perfer c89 for all my stuff, and then I use
C90 when I need to use long long or unsigned long long.


Great!!!

But that is not standard C. Clear?
 
M

Mark McIntyre

Hi
I'm coding this simple program, but I get a segmentation fault, I'm
pretty sure that the arrays are big enough and there isn't really any
buffer overflows

Apart from the off-by-one errors....
double vsum(double x[20], int n){
int i;
float Result = 0;

//Calculation for - Sum of numbers
for (i=1;i<=n;i++){
Result += x;


C arrays start from zero. If n = 20 then this will write to the 21st
element of x, which doesn't exist. Additionally you're not including
the first element of the array in your sum...

Of course its /possible/ to write VB-style 1-based arrays in C, but
seriously, this is a Bad Idea as no other C programmer will do it.
int NumOfNum; // Number "n" of numbers to be entered ....
scanf(" %f", &NumOfNum);

format specifier incorrect.
//Adds numbers into array & calculation for sum of numbers
for (i=0;i<=NumOfNum;i++){

you want to loop to Less than NumofNum - think about it.
Mean_1 = Sum_1 / NumOfNum;

The format specifier error means that NumofNum is probably zero,
and...

--
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
 
M

Mark McIntyre

(e-mail address removed) a écrit :

// comments are standard C. Mr Rudy is completely wrong.

He's not /completely/ wrong. The vast majority of extant C compilers
will reject C++ style comments when invoked in conforming mode, since
tehy conform to C89. A few, such as recentish releases of gcc, will
accept them since tehy conform to C99.
--
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
 
M

Mark McIntyre

The C99 standard is the current standard. Others have only an historical
interest.

Given that its likely that the /overwhelming/ majority of C compilers
in commercial use don't conform to C99, that remark seems absurd.
--
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
 
I

Ian Collins

Daniel said:
At about the time of 4/10/2007 2:19 PM, Ian Collins stated the following:


Not you too.
Yes, me too.
I always use -std=c89 -ansi options when I compile my code. Sometimes I
use -std=iso9899:199409 for C90 standard when I need it. I don't need
or have the desire to code to C99, especially when it's only partly
implemented.
I don't realy care about comment style, it's up to the individual
developer which they use and to which standard they want their code to
conform. So I don't rant and rail about such trivia and I don't make
futile attempts to impose my choice of standard on others.
 
M

Mark McIntyre

Richard Heathfield a écrit :
Excuse me, I have yet to find a C compiler that does NOT accept
// comments.

Jacob, please don't be so obtuse. It just makes you look foolish.
Please show me *some* example for those...

Anything from Microsoft, for example, when invoked in conforming mode.

--
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
 
M

Mark McIntyre

Richard Heathfield a écrit :

It accepts those comments since at least
1995 or even earlier. In any case, since 1995
they are accepted in C mode. This is just a lie.

Not one of the above compilers will accept // comments *if invoked as
a conforming C compiler*. There's no option to engage C99 compliance
either, since they all predate that standard.
Gcc accepts // comments in C mode unles you force it not to.

Incorrect. Even gcc 4.x will emit an error if you tell it to conform
to ANSI or C89 standards.
This is a lie too.

One day, someone is going to call you on this, and you'll end up in
court paying damages for libel or slander or whatever it is.

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top