Sponsored Content
Top Forums Programming fread: segementation fault(coredump) w/o stdlib.h Post 302286608 by Corona688 on Wednesday 11th of February 2009 02:23:54 PM
Old 02-11-2009
As the doctor would say, "don't do that". Smilie Either AIX has odd integer sizes, or you're on a 64-bit system. Or perhaps both.

When you use functions that you haven't included headers for, the compiler's forced to guess what parameters the function takes and returns, and will guess they are all integers. This is often a good guess on most 32-bit systems, where int, long, and all pointers are the same size -- 32 bits. But 64-bit systems will have 64-bit pointers while still perhaps having 32-bit integers, causing pointers to get balled up and crammed through the mail slot, so to speak.

Without stdlib.h, the value malloc() gives you is corrupted, causing fread to crash when it uses it.

So, always include the headers! Just because it works 'this time' when you don't doesn't mean it will in all situations.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Coredump (memory fault)

We are running a SQR program on Unix Platform with Oracle RDBMS. It's an interfacing program to integrate data from foreign sites to PeopleSoft database, using a flat file input. After many hours of processing, the program stops with a coredump error (memory fault). With top command we noticed... (1 Reply)
Discussion started by: araziki
1 Replies

2. Programming

Memory fault(coredump)

Dear All, I made a program which do some simple jobs like reading data from other process's shared memory and writing messages to the queues of other process. what happens is my program works fine and do all the task as expected but then then program ends it give Memory fault(coredump). I... (0 Replies)
Discussion started by: ralo
0 Replies

3. Shell Programming and Scripting

Awk:Segementation Fault

I am using awk command to sort a large file (7MB) and compare two files of 7 MB. The code is working fine for smaller files. But it gives following error for larger files Segmentation fault (core dumped) I am doing this on cygwin Please help in this regard Thanks Sandeep (1 Reply)
Discussion started by: sandeep_hi
1 Replies

4. Programming

Passed the compiler,but segementation fault

To find a number if it is a prime number, I cannot find any wrong. #include <stdio.h> #include <stdlib.h> int isPrime(int valToCheck) { int i; int retVal = 1; for(i=1;i<valToCheck;i++) { if(valToCheck%i == 0 && i != 1) { retVal = 0; ... (1 Reply)
Discussion started by: zhshqzyc
1 Replies

5. AIX

Segmentation fault(coredump)

Hi All Can anybody help me? When ever am trying to run topas system gives me an error Segmentation fault(coredump) does anybody ahve solution for this? (4 Replies)
Discussion started by: vjm
4 Replies

6. Ubuntu

Memory fault(coredump)

Hey guys, I am new to the Linux world and have a question to post. When I ssh from a HP-UX machine to a ubuntu machine I get the following error message Memory fault(coredump) i.e. ssh 192.168.1.3 I get this message as shown below Memory fault(coredump) Can someone please explain... (2 Replies)
Discussion started by: fkaba81
2 Replies

7. Solaris

memory fault (coredump)

Getting memory fault (coredump) and segmentation fault(coredump) when i tried javac or java -version. what could be the problem? Regards Eswar (2 Replies)
Discussion started by: BhuvanEswar
2 Replies

8. Shell Programming and Scripting

Segmentation Fault(coredump)

I'm getting this error when trying to run a Acucobol program thru UNIX.. Segmentation Fault(coredump) Precompiler error prevents compilation of xxxxxx.co. Please help me in this case.. (1 Reply)
Discussion started by: Manish4
1 Replies

9. Homework & Coursework Questions

Memory fault(coredump)

I am writing a program that copies a program and prints the program with a line count. this is the program I wrote: #include <stdio.h> main() { int c; int nl_cnt = 0; while((c = getchar()) != EOF){ if(c = '\n'){ nl_cnt++;... (3 Replies)
Discussion started by: heywoodfloyd
3 Replies

10. UNIX for Advanced & Expert Users

Memory fault(Coredump)

Hi, In my application we have one job which is used to process the files. But that job is failing with memory fault while processing a file or while shutting down the job. Sometime it generates the coredump and sometimes not. When I analysed the core dump I got below code snippet where it... (3 Replies)
Discussion started by: shilpa_20
3 Replies
portal(5)							File Formats Manual							 portal(5)

NAME
portal - a "window to the future" for applications SYNOPSIS
DESCRIPTION
This header file is a "window to the future" for applications. It will help you to: o Write code that is portable across 32-bit and 64-bit systems, o Avoid undocumented assumptions about sizes of integral types, o Write portable code that needs to be explicit about the sizes of integral types, o Write code that is portable to a platform which has different sizes of integral types, and o Share frequently used macros that are portable across 32-bit and 64-bit systems. In addition to the macros defined in this file, it includes the header files (see limits(5)) and (see inttypes(5)). The following macros are defined in This macro can be used to create a mask that has one bit set. bit_num is the position of the bit to set, and type is the data type of the mask. A -1 is returned in the case of overflow or underflow. This macro can be used to set a bit in a mask. mask is the current value of the mask, bit_num is the position of the bit to set, and type is the data type of the mask. This macro can be used to return the bit position of the sign bit for the specified data type. type is the data type for which to return the position of the sign bit. This macro can be used to return a mask for the sign bit for the specified data type. type is the data type for which to return the sign bit mask. This macro can be used to do a sign extension from one data type to another. value is the current value that is to be sign-extended. old_type is the current data type of value and new_type is the new data type of value. This macro can be used to check if code has been compiled big or little endian. endian is an integer in which the result will be returned. The following macros can be used for print formatting and scan formatting of values of data types that can change in size based upon the compilation flag Examples of such data types are off_t and fpos_t. EXAMPLES
The macro in the following example will turn on the high bit in a 64-bit integer. The macro in the following example will be used to turn on all bits except the sign bit in a 32-bit integer. The macro in the following example will turn on the three least significant bits of the maximum integer. The macro in the following example will return the position of the sign bit in a 32-bit integer. The macro in the following example will return a sign bit mask for a 32-bit integer. The macro in the following example will convert the 8-bit integer stored in a char data type to a 64-bit integer and correctly extend the sign. The macro in the following example will store a 1 in endian if the compilation was big endian; otherwise, it will store a 0 in endian. AUTHOR
was developed by HP. FILES
SEE ALSO
inttypes(5), limits(5), printf(3S), scanf(3S). portal(5)
All times are GMT -4. The time now is 10:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy