Sponsored Content
Full Discussion: C code : Segmentation fault
Top Forums Programming C code : Segmentation fault Post 302492414 by Corona688 on Monday 31st of January 2011 10:15:38 AM
Old 01-31-2011
What is your system?

What is your compiler?

In gcc/linux, compile with -ggdb and run with gdb ./a.out, then type 'run', and when it crashes, type 'bt full' to show where it crashed.

Also: Listen to the warnings the compiler gives you. to wit:

Code:
definitions.h:10: warning: 'SRC_DIR' initialized and declared 'extern'
definitions.h:11: warning: 'LOG_DIR' initialized and declared 'extern'
definitions.h:12: warning: 'TMP_DIR' initialized and declared 'extern'
definitions.h:13: warning: 'ARCH_DIR' initialized and declared 'extern'
definitions.h:16: warning: 'LOG_NAME' initialized and declared 'extern'
definitions.h:17: warning: 'FIELD_SEP' initialized and declared 'extern'
definitions.h:18: warning: 'LOG_EXT' initialized and declared 'extern'
definitions.h:19: warning: 'TMP_EXT' initialized and declared 'extern'
definitions.h:20: warning: 'TRG_EXT' initialized and declared 'extern'
definitions.h:21: warning: 'ARCH_EXT' initialized and declared 'extern'
definitions.h:22: warning: 'DIR_SEP' initialized and declared 'extern'
port.c: In function 'main':
port.c:80: warning: format '%s' expects type 'char *', but argument 2 has type 'char **'
port.c:14: warning: unused variable 'target_stream'

header files don't work that way, and extern doesn't work that way. You either want to do

Code:
#define SRC_DIR "/home/hhulaman/1516/source/"

or
Code:
extern char * SRC_DIR;

with an accompanying
Code:
#include "definitions.h"
char *SRC_DIR="/home/hhulaman/1516/source/";

in definitions.c. This prevents the variable from being redefined 19 times if it's included in 19 seperate C files.

Better yet, make them constant, so you can't overwrite them accidentally:
Code:
extern const char const * SRC_DIR;


Last edited by Corona688; 01-31-2011 at 11:22 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

segmentation fault

sometimes for this code i get a segmentation fault for codes llike this : int main{ int * a= 0; int b; a = (int*)malloc(sizeof(int)); ///some code using these variable but no freeing of a if(a){ free(a); a = 0; } return... (3 Replies)
Discussion started by: wojtyla
3 Replies

2. Programming

Hi! segmentation fault

I have written a program which takes a directory as command line arguments and displays all the dir and files in it. I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
Discussion started by: vijlak
4 Replies

3. Programming

segmentation fault

If I do this. Assume struct life { char *nolife; } struct life **life; // malloc initialization & everything if(life->nolife == 0) Would I get error at life->nolife if it is equal to 0. wrong accession? (3 Replies)
Discussion started by: joey
3 Replies

4. AIX

Segmentation fault in nsgetcinfo in aix 64-bit c code

Hello, I am running on a AIX5.2 server with Oracle 10g and 9i. My code compiles and works fine in 32-bit mode. The same code compiles in 64-bit and runs good. The program catches CNTRL-C signal to terminate. Only on 64-bit code when i hit CNTRL-C, the program exits with segmentation... (0 Replies)
Discussion started by: sumesh0710
0 Replies

5. Programming

segmentation fault

Hi, I am having this segmentation fault not in the following program, bt. in my lab program . My lab program is horrible long so cannot post it here bt. I am using the following logic in my program which is giving the segmentation fault. Bt. if I run this sample program as it is it dosen't give... (3 Replies)
Discussion started by: mind@work
3 Replies

6. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

7. Programming

This code keeps giving me a segmentation fault why?

#include<stdlib.h> #include <pthread.h> #include "tlpi_hdr.h" #include <stdio.h> static volatile int glob = 0; static struct { pthread_t t1,t2; } *thread; static void * /* Loop 'arg' times incrementing 'glob' */ threadFunc(void *arg) { int loops = *((int *) arg); ... (1 Reply)
Discussion started by: fwrlfo
1 Replies

8. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

9. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies

10. Programming

Why does this example C code run and yet SHOULD either not compile or give a segmentation fault?

Apologies for any typos... Well guys, been researching 'goto' in C and they say that you can't 'goto' labels in another function as a segmentation fault will occur. However I have found a way to 'goto' a label in another function that is NOT main() using the asm() function. As you know I... (14 Replies)
Discussion started by: wisecracker
14 Replies
Padre::Task::Eval(3pm)					User Contributed Perl Documentation				    Padre::Task::Eval(3pm)

NAME
Padre::Task::Eval - Task for executing arbitrary code via a string eval SYNOPSIS
my $task = Padre::Task::Eval->new( prepare => '1 + 1', run => 'my $foo = sub { 2 + 3 }; $foo->();', finish => '$_[0]->{prepare}', ); $task->prepare; $task->run; $task->finish; DESCRIPTION
Padre::Task::Eval is a stub class used to implement testing and other miscellaneous functionality. It takes three named string parameters matching each of the three execution phases. When each phase of the task is run, the string will be eval'ed and the result will be stored in the same has key as the source string. If the key does not exist at all, nothing will be executed for that phase. Regardless of the execution result (or the non-execution of the phase) each phase will always return true. However, if the string eval throws an exception it will escape the task object (although when run properly inside of a task handle it should be caught by the handle). METHODS
This class contains now additional methods beyond the defaults provided by the Padre::Task API. COPYRIGHT &; LICENSE Copyright 2008-2012 The Padre development team as listed in Padre.pm. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-27 Padre::Task::Eval(3pm)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy