I just finish writing LAB2 with no errors when compiling, but once i run
it, i get "segmentati on fault".. i don't know what is wrong, can anyoen
tell me what it means and how i can fix it? thx!
Nov 14 '05
21 8310
"Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message
news:sl******** ***********@heh e.cl.cam.ac.uk. .. Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message news:sl******** ***********@heh e.cl.cam.ac.uk. .. Peter Pichler wrote: > > Yes. The statistics show that 100% of segmentation faults are caused
by > derefencing an invalid pointer.
$ cat recurse.c int main() { return main(); } $ gcc -ansi -pedantic recurse.c $ ./a.out Segmentation fault
Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become invalid?
Isn't calling a function dereferencing a function pointer?
This is a genuine question, I am not so sure any more.
Peter
Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message news:sl******** ***********@heh e.cl.cam.ac.uk. .. Peter Pichler wrote: > "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message > news:sl******** ***********@heh e.cl.cam.ac.uk. .. >> Peter Pichler wrote: >> > >> > Yes. The statistics show that 100% of segmentation faults are caused by >> > derefencing an invalid pointer. >> >> $ cat recurse.c >> int main() { return main(); } >> $ gcc -ansi -pedantic recurse.c >> $ ./a.out >> Segmentation fault > > Your example involves dereferencing an invalid pointer. Really? At which point, and for what reason, does the pointer become invalid?
Isn't calling a function dereferencing a function pointer? This is a genuine question, I am not so sure any more.
I believe you're correct. (Since, I am watching my mouth as far as
interpreting the standard for the general public goes, I won't assert that
you're correct :-)
From 6.3.2.1:
4 A function designator is an expression that has function type. Except when
it is the operand of the sizeof operator54) or the unary & operator, a
function designator with type "function returning type" is converted to an
expression that has type "pointer to function returning type".
Further, 6.5.2.2 Function Calls:
1 The expression that denotes the called function77) shall have type pointer
to function returning void or returning an object type other than an array
type.
77) Most often, this is the result of converting an identifier that is a
function designator.
-nrk.
Peter
--
Remove devnull for email
Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message news:sl******** ***********@heh e.cl.cam.ac.uk. .. Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message news:sl******** ***********@heh e.cl.cam.ac.uk. .. > Peter Pichler wrote: > > > > Yes. The statistics show that 100% of segmentation faults are caused by> > derefencing an invalid pointer. > > $ cat recurse.c > int main() { return main(); } > $ gcc -ansi -pedantic recurse.c > $ ./a.out > Segmentation fault
Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become invalid?
Isn't calling a function dereferencing a function pointer? This is a genuine question, I am not so sure any more.
The second appearance of `main' is in fact a function
pointer, and the `()' function-call operator uses that pointer
value to determine what function to invoke. Whether this use
constitutes a "dereferenc e" is unclear -- the Standard neither
defines nor uses the word.
At any rate, the function pointer value `main' remains
valid for the life of the program. Thus, the call is not
"dereferenc ing an invalid pointer" because the pointer is
not invalid.
-- Er*********@sun .com
On 6 Feb 2004 22:22:58 GMT, in comp.lang.c , Jeremy Yallop
<je****@jdyallo p.freeserve.co. uk> wrote: Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote in message news:sl******** ***********@heh e.cl.cam.ac.uk. .. Peter Pichler wrote: > > Yes. The statistics show that 100% of segmentation faults are caused by > derefencing an invalid pointer.
$ cat recurse.c int main() { return main(); } $ gcc -ansi -pedantic recurse.c $ ./a.out Segmentation fault
Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become invalid?
when you run out of memory .
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Martin Ambuhl <ma*****@earthl ink.net> wrote in message news:<DT******* ************@ne wsread1.news.at l.earthlink.net >... us**@domain.inv alid wrote:
I just finish writing LAB2 with no errors when compiling, but once i run it, i get "segmentati on fault".. i don't know what is wrong, can anyoen tell me what it means and how i can fix it? thx!
Stop dereferencing invalid pointers.
What happened to our OTNs (off-topic Nazis). Why aren't they stomping
the guts out of these people saying "segmentati on ain't in our
bible^Wstandard !" :-)
MSG (no, I'm not an OTN) us**@domain.inv alid wrote: I just finish writing LAB2 with no errors when compiling but once i run it, I get "segmentati on fault". I don't know what is wrong, Can anyone tell me what it means and how I can fix it?
Your program is attempting to reference memory
which doesn't belong to it.
You probably have an array index which is "out-of-bounds".
Use your debugger. If you don't have a debugger or know how to use it,
you can insert statements to print diagnostic messages
fprintf(stderr, "Got to this point in the program!\n"); fflush(stderr);
Put the first one smack dab in the middle of your code.
If you get the "segmentati on fault" before the diagnostic message
you know that the error is before the print statement and
the error is after the print statement
if you get the diagnostic message before the "segmentati on fault".
A short binary search usually locates the error quickly.
Jeremy Yallop wrote: Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote Peter Pichler wrote: > > Yes. The statistics show that 100% of segmentation faults > are caused by derefencing an invalid pointer.
$ cat recurse.c int main() { return main(); } $ gcc -ansi -pedantic recurse.c $ ./a.out Segmentation fault
Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become invalid?
Also, what pointer? To make sure, add void in "int main(void)"
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Eric Sosman wrote: Peter Pichler wrote: "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote Peter Pichler wrote: > "Jeremy Yallop" <je****@jdyallo p.freeserve.co. uk> wrote >> Peter Pichler wrote: >> > >> > Yes. The statistics show that 100% of segmentation faults >> > are caused by derefencing an invalid pointer. >> >> $ cat recurse.c >> int main() { return main(); } >> $ gcc -ansi -pedantic recurse.c >> $ ./a.out >> Segmentation fault > > Your example involves dereferencing an invalid pointer.
Really? At which point, and for what reason, does the pointer become invalid?
Isn't calling a function dereferencing a function pointer? This is a genuine question, I am not so sure any more.
The second appearance of `main' is in fact a function pointer, and the `()' function-call operator uses that pointer value to determine what function to invoke. Whether this use constitutes a "dereferenc e" is unclear -- the Standard neither defines nor uses the word.
At any rate, the function pointer value `main' remains valid for the life of the program. Thus, the call is not "dereferenc ing an invalid pointer" because the pointer is not invalid.
I was going to be a smart-ass and point out that compiling with
gcc -O2 did not generate the segment fault, because of tail
recursion optimization. Luckily I tried it first, and found that
gcc does NOT optimize this one. Must be a feature, couldn't
possibly be a bug.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
"Emmanuel Delahaye" <em**********@n oos.fr> wrote in message
news:Xn******** *************** ****@212.27.42. 68... In 'comp.lang.c', "E. Robert Tisdale" <E.************ **@jpl.nasa.gov >
wrote: fprintf(stderr, "Got to this point in the program!\n"); fflush(stderr);
I'm not sure thar stderr is buffered, hence the fflush() seems redunant. Also, the line is terminated by a '\n', that makes the fflush() twice redundant. What would be more informative would have been to add smart information like the file name and the line in the file:
fprintf (stderr, "Got to here %s:%d in the program!\n", __FILE__,
__LINE__);
A nitpick here is that __LINE__ is not guaranteed to have int type.
--
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sivignon |
last post by:
Hi,
I'm writing a php script which deals with 3 ORACLE databases.
This script is launch by a script shell on an linux machine like this :
/../php/bin/php ./MySript.php (PHP 4.3.3)
My script works fine and do all what I need.
But at the end of the execution, I can read "Segmentation Fault".
The segmentation fault appear at the end of my script execution,
|
by: diyanat |
last post by:
i am writing a cgi script in C using the CGIC library, the script
fails to run, i am using apache on linux
error report from apache : internal server error
Premature end of script headers: /var/www/cgi-bin/script.cgi
when i debug the program i get Segmentation fault
gdb ./script.cgi
|
by: laberth |
last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why?
Here is what I use :
typedef struct noeud {
int val;
struct noeud *fgauche;
struct noeud *fdroit;
} *arbre; //for those who don't speak french arbre means tree.
|
by: Zheng Da |
last post by:
Program received signal SIGSEGV, Segmentation fault.
0x40093343 in _int_malloc () from /lib/tls/libc.so.6
(gdb) bt
#0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6
#1 0x40094c54 in malloc () from /lib/tls/libc.so.6
It's really strange; I just call malloc() like "tmp=malloc(size);"
the system gives me Segmentation fault
I want to write a code to do like a dynamic array, and the code is as
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I understood that a segmentation
fault can occur whenever I declare a pointer and I leave it
un-initialized.
So I thought the problem here is with the (const char *)s in the stuct
flightData (please note that I get the same fault declaring as char *
the...
| |
by: Digital Puer |
last post by:
Hi, I'm coming over from Java to C++, so please bear with me.
In C++, is there a way for me to use exceptions to catch
segmentation faults (e.g. when I access a location off
the end of an array)?
Thanks.
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
#include <stdlib.h>
#include <stdio.h>
typedef struct _node_t {
|
by: pycraze |
last post by:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.
If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in...
|
by: madunix |
last post by:
My Server is suffering bad lag (High Utlization)
I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2
Web visitors retrieve data from the web by php calls through oci
cobnnection from 10g release2
PHP is configured with the following parameters
'./configure' '--prefix=/opt/oracle/php'
'--with-apxs=/opt/oracle/apache/bin/apxs'
'--with-config-file-path=/opt/oracle/apache/conf' '--enable-safe-mode'
'--enable-session'...
|
by: DanielJohnson |
last post by:
int main()
{
printf("\n Hello World");
main;
return 0;
}
This program terminate just after one loop while the second program
goes on infinitely untill segmentation fault (core dumped) on gcc. The
only difference is that in first I only call "main" and in second call
|
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: 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,...
|
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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |