Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

segmentation fault (SIGSEGV)

47 views
Skip to first unread message

Benjamin

unread,
Jun 1, 2010, 10:53:15 AM6/1/10
to

After compiling the whole codes without no errors, I'm getting into
the trouble of "segmentation fault" when I try to run the executable
file.
It's a little bit annoying....
Although I've known it's generated by several factors:
# An array index is outside the declared range.
# The name of an array index is misspelled.
# The calling routine has a REAL argument, which the called routine
has as INTEGER.
# An array index is miscalculated.
# The calling routine has fewer arguments than required.
# A pointer is used before it has been defined.
....I can't find the fatal factor(s).

But is there any software or package to check this progress?
My OS is openSUSE 11.0, the compiler is SCons.


steve

unread,
Jun 1, 2010, 10:59:35 AM6/1/10
to

Scons appears to be some sort of integrated build environment.
What is the actual Fortran compiler installed on your system?

--
steve

Benjamin

unread,
Jun 1, 2010, 11:01:41 AM6/1/10
to

Oh, sry, gFortran is the actual comiler

Alois Steindl

unread,
Jun 1, 2010, 11:02:37 AM6/1/10
to
Hello,
a debugger might be a great help in this situation.
If you are planning to dig deep into programming,
learning to use the available debuggers is a worthwhile option.

Another possible reason: Too small memory sizes, like stack size.
Can usually be corrected with ulimit.

Good luck
Alois

mecej4

unread,
Jun 1, 2010, 11:56:14 AM6/1/10
to
Benjamin wrote:

1. Compile with the checking options of your compiler set ON
(e.g., -C -traceback ... check your compiler options list see what to use)

AND/OR

2. Compile with -g, and use tools such as GDB and VALGRIND.

Once you establish that the seg-fault is traceable to your code, you may see
it as a good thing, if the alternative is to propagate erroneous results
throughout your program with no notification to you.

Compiling without errors merely establishes that those errors that are
detectable by static analysis of the code have been removed. By no means
does it follow that there are no more errors left in the code.

-- mecej4

Benjamin

unread,
Jun 1, 2010, 12:14:04 PM6/1/10
to

Thanks a lot.
I've complied the program with SCons...
now I'm trying to debug the program with gdb..

steve

unread,
Jun 1, 2010, 12:17:57 PM6/1/10
to

With gfortran try the compiler options '-fbounds-check -Wall -Wextra -
g'.
The -Wall and -Wextra option will most likely produce a large amount
that (IMHO) should be fixed. -fbounds-check should help catch array
index issues.

--
steve

dpb

unread,
Jun 1, 2010, 12:23:57 PM6/1/10
to
Benjamin wrote:
...

> Thanks a lot.
> I've complied the program with SCons...
> now I'm trying to debug the program with gdb..

As others have noted, use all available error trapping and traceback
options first.

One could also disable optimization until the problem(s) is/are resolved
as well as it may make determination of just where something went sought
somewhat easier.

Rarely would there be no clues or breadcrumbs to follow after such has
been done...

--

Louis Krupp

unread,
Jun 1, 2010, 4:08:09 PM6/1/10
to
On 6/1/2010 8:53 AM, Benjamin wrote:
>
> After compiling the whole codes without no errors, I'm getting into
> the trouble of "segmentation fault" when I try to run the executable
> file.
> It's a little bit annoying....
> Although I've known it's generated by several factors:

<snip>


> # The name of an array index is misspelled.

Use "implicit none" if you're not doing so already. You'll have to
declare all of your variables, and unless you declare two variables with
very similar names, the compiler is likely to catch misspellings.

> # The calling routine has a REAL argument, which the called routine
> has as INTEGER.

<snip>


> # The calling routine has fewer arguments than required.

<snip>

Use modules. The compiler will convert arguments as necessary (someone
want to verify this?) or flag argument list mismatches.

Louis

Ron Shepard

unread,
Jun 1, 2010, 11:40:25 PM6/1/10
to
In article <5KWdnQAwhvwt9ZjR...@indra.net>,
Louis Krupp <lkrupp...@indra.com.invalid> wrote:

>
> Use modules. The compiler will convert arguments as necessary

No, nothing is converted.

> (someone
> want to verify this?)

You must be thinking of some other language. Other languages do
sometimes do silent conversions to match arguments.

> or flag argument list mismatches.

This part *IS* right, and that's one of the reasons why modules are so
useful.

$.02 -Ron Shepard

Louis Krupp

unread,
Jun 2, 2010, 3:41:14 AM6/2/10
to
On 6/1/2010 9:40 PM, Ron Shepard wrote:
> In article<5KWdnQAwhvwt9ZjR...@indra.net>,
> Louis Krupp<lkrupp...@indra.com.invalid> wrote:
>
>>
>> Use modules. The compiler will convert arguments as necessary
>
> No, nothing is converted.
>
>> (someone
>> want to verify this?)
>
> You must be thinking of some other language. Other languages do
> sometimes do silent conversions to match arguments.

So reals aren't truncated to integers?

Louis


dpb

unread,
Jun 2, 2010, 8:01:38 AM6/2/10
to
Louis Krupp wrote:
> On 6/1/2010 9:40 PM, Ron Shepard wrote:
...

>> You must be thinking of some other language. Other languages do
>> sometimes do silent conversions to match arguments.
>
> So reals aren't truncated to integers?

In argument lists? No, a REAL in a CALL statement for a routine
expecting an INTEGER will generate a mismatched argument type error (in
the module during compilation) and a mismatched call if forced to link
outside of one where a compiler may not be able to tell of the mismatch.

--

mecej4

unread,
Jun 2, 2010, 8:24:11 AM6/2/10
to
dpb wrote:

To add to what dpb said: If the expected INTEGER is used as a subscript but
a real (or another mismatched type) was passed instead, a prompt SEGFAULT
may be expected.

-- mecej4

Louis Krupp

unread,
Jun 2, 2010, 8:54:12 AM6/2/10
to

Likely (given the format of IEEE floating point, for example), but not
necessarily (if a high virtual address plus garbage with high-order bits
turned on wrap around to a low, valid virtual address).

The same thing would happen in that Other Language with which I'm more
familiar.

Louis

Ron Shepard

unread,
Jun 2, 2010, 2:19:02 PM6/2/10
to
In article <8-GdnX9H3cm8lpvR...@indra.net>,
Louis Krupp <lkrupp...@indra.com.invalid> wrote:

> > You must be thinking of some other language. Other languages do
> > sometimes do silent conversions to match arguments.
>
> So reals aren't truncated to integers?

No. Actually I can't think of any situation offhand where reals are
truncated to integers. In some contexts, such as mixed arithmetic,
integers are silently converged to reals, but I can't think of any
situations where the reverse occurs. And especially for subprogram
arguments, no conversion is ever done silently, not even between
different kinds of the same type, much less between different types.

$.02 -Ron Shepard

glen herrmannsfeldt

unread,
Jun 2, 2010, 6:33:54 PM6/2/10
to
Ron Shepard <ron-s...@nospam.comcast.net> wrote:
(snip, someone wrote)


>> So reals aren't truncated to integers?

> No. Actually I can't think of any situation offhand where reals are
> truncated to integers. In some contexts, such as mixed arithmetic,
> integers are silently converged to reals, but I can't think of any
> situations where the reverse occurs. And especially for subprogram
> arguments, no conversion is ever done silently, not even between
> different kinds of the same type, much less between different types.

Well, reals are truncated on assignment to an integer variable,
but maybe you don't count that.

Some systems allow real expressions for subscripts, truncating
the value to an integer.

Or course the intrinsic functions specifically designed to
convert non-integer values to integers, as appropriate.

But yes, it is not done for subroutine arguments.

-- glen

steve

unread,
Jun 2, 2010, 7:02:45 PM6/2/10
to
On Jun 2, 3:33 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:

> Ron Shepard <ron-shep...@nospam.comcast.net> wrote:
>
> (snip, someone wrote)
>
> >> So reals aren't truncated to integers?
> > No.  Actually I can't think of any situation offhand where reals are
> > truncated to integers.  In some contexts, such as mixed arithmetic,
> > integers are silently converged to reals, but I can't think of any
> > situations where the reverse occurs.  And especially for subprogram
> > arguments, no conversion is ever done silently, not even between
> > different kinds of the same type, much less between different types.
>
> Well, reals are truncated on assignment to an integer variable,
> but maybe you don't count that.
>
> Some systems allow real expressions for subscripts, truncating
> the value to an integer.
>
troutmask:sgk[218] cat > k.f
program ohmy
real x(3)
x = (/ 1, 2, 3 /)
print *, x(2.1)
end
troutmask:sgk[219] gfc4x -o z k.f
k.f:4.17:

print *,
x(2.1)
1
Warning: Extension: REAL array index at (1)
troutmask:sgk[220] ./z
2.0000000

--
steve

Craig Powers

unread,
Jun 3, 2010, 8:52:04 PM6/3/10
to

Certainly not with non-VALUE arguments, but that's true of just about
any language I might care to mention; it just becomes obvious with C,
C++, etc. because they use value arguments so frequently.

Although I don't think there's a strong technical reason for it, it does
not appear that Fortran will do any automatic conversion for numeric
VALUE arguments. It seems like something that could be put in without
an obnoxious amount of effort considering that the text of the '03
standard already says, "If the VALUE attribute is specified, the effect
is as if the actual argument is assigned to a temporary, and the
temporary is then argument associated with the dummy argument." (But
that's in a Note, and the normative text requires that the actual
argument be type-compatible with non-pointer, non-allocatable dummy with
no qualifications.)

Richard Maine

unread,
Jun 3, 2010, 9:09:25 PM6/3/10
to
Craig Powers <craig....@invalid.invalid> wrote:

> Although I don't think there's a strong technical reason for it, it does
> not appear that Fortran will do any automatic conversion for numeric
> VALUE arguments. It seems like something that could be put in without

> an obnoxious amount of effort...

other than completely blowing generics out of the water. :-(

And maybe a few other things, but that one immediately occurs to me.

Plus, of course, being completely unlike any other procedure arguments
in the language, which would be bound to cause no end of confusion. It
sure seems a lot simpler and more consistent to just be able to say that
arguments must match and there is never any conversion instead of having
to add "well, except in this one special class of cases, where it is
different just because it could be."

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

Richard Maine

unread,
Jun 3, 2010, 9:24:24 PM6/3/10
to
Richard Maine <nos...@see.signature> wrote:

> Craig Powers <craig....@invalid.invalid> wrote:
>
> > Although I don't think there's a strong technical reason for it, it does
> > not appear that Fortran will do any automatic conversion for numeric
> > VALUE arguments. It seems like something that could be put in without
> > an obnoxious amount of effort...
>
> other than completely blowing generics out of the water. :-(
>
> And maybe a few other things, but that one immediately occurs to me.

A related one that occurred to me right after posting that is all the
stuff about how procedure resolution works. Admitedly, that is related
in that generics get all tied up with it. But I'd call it an additional
complication because it would still need work even if one came up with
some rule to make it compatible with generics. In fact, any such rule
would have to be stuck right in the middle of the the procedure name
resolution stuff.

That's one of the messier few pages of the standard. The only reason it
doesn't generate zillions of questions here is that almost all of the
cases in real programs are dead trivial; when you call a procedure by
name, there is usually only one accessible procedure with that name and
that's the one you get. Anything that touches those particular messy
pages counts as a pretty obnoxious amount of effort in my book.

glen herrmannsfeldt

unread,
Jun 3, 2010, 9:40:23 PM6/3/10
to
Craig Powers <craig....@invalid.invalid> wrote:
(snip)


> Certainly not with non-VALUE arguments, but that's true of just about
> any language I might care to mention; it just becomes obvious with C,
> C++, etc. because they use value arguments so frequently.

PL/I will do it under the appropriate conditions, generating
a temporary and passing that. The value won't be written back
to the original variable, so you have to be careful.



> Although I don't think there's a strong technical reason for it, it does
> not appear that Fortran will do any automatic conversion for numeric
> VALUE arguments.

It makes some sense for BIND(C) VALUE arguments, as C would
do it with a prototype in scope.

> It seems like something that could be put in without
> an obnoxious amount of effort considering that the text of the '03
> standard already says, "If the VALUE attribute is specified, the effect
> is as if the actual argument is assigned to a temporary, and the
> temporary is then argument associated with the dummy argument." (But
> that's in a Note, and the normative text requires that the actual
> argument be type-compatible with non-pointer, non-allocatable dummy with
> no qualifications.)

-- glen

Richard Maine

unread,
Jun 3, 2010, 10:02:56 PM6/3/10
to
glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:

> Craig Powers <craig....@invalid.invalid> wrote:

>
> > Although I don't think there's a strong technical reason for it, it does
> > not appear that Fortran will do any automatic conversion for numeric
> > VALUE arguments.
>
> It makes some sense for BIND(C) VALUE arguments, as C would
> do it with a prototype in scope.

As noted in other threads, Fortran isn't C. And no, I don't buy the
"this was just for comparison purposes." Sure reads like an explicit
suggestion to put in into Fortran to me.

"C does it" isn't much of a reason to argue that something should be
done in Fortran. It actually has to fit in the Fortran language. Yes,
that is so even for BIND(C) procedures. C does lots of things in
function calls that Fortran doesn't do.

Earlier today or yesterday you were suggesting that something be more
consistent. Now you want to make BIND(C) VALUE arguments behave
fundamentally different from all other arguments, including other
BIND(C) and other VALUE arguments; one has to have both to trigger the
special case? This for no reason other than that C does it? You appear
to have a different notion of consistency than I do.

Do note, by the way, that just because a procedure is BIND(C), that
doesn't mean it is necessarily a procedure written in C.

But I don't know why I bother to post this. It ain't going to happen. No
way. As noted in my other post, it would invalidate existing standard
conforming codes by badly breaking generics. Yes, I'd bet there are
existing codes that use BIND(C) procedures in generics. It is a natural
thing to do. While incompatibilities like that have been known to
happen, they tend to fall into one of 2 classes.

1. The incompatibility was not noticed until after the new standard was
published. Often that isn't even enough, as there have been known to be
errata to fix that kind of problem. Such an unnoticed incompatibility
has more than once been cited as being an adequate reason for an errata.
But this one isn't unnoticed. It wouldn't be unnoticed even if I hadn't
pointed out. It is a glaring big incompatibility.

or

2. There is darn good justification given. Nothing here has been even
close to the kind of justification that tends to be needed. If you think
otherwise, well.... lots of luck. I'll be confident inmy claim that it
ain't gonna happen.

Craig Powers

unread,
Jun 3, 2010, 10:38:17 PM6/3/10
to
Richard Maine wrote:
> Craig Powers <craig....@invalid.invalid> wrote:
>
>> Although I don't think there's a strong technical reason for it, it does
>> not appear that Fortran will do any automatic conversion for numeric
>> VALUE arguments. It seems like something that could be put in without
>> an obnoxious amount of effort...
>
> other than completely blowing generics out of the water. :-(
>
> And maybe a few other things, but that one immediately occurs to me.

Oops, yeah, I forgot about that.

C++ manages it, but from what I recall when I followed C++ more closely,
conversion and overload matching rules are a consistent sore point.
There are definitely dragons there, so it would make sense to stay away
with Fortran.

0 new messages