Sponsored Content
Top Forums Programming Segmentation fault in fopen when in write mode. Post 302672519 by alister on Monday 16th of July 2012 12:31:24 PM
Old 07-16-2012
You are mistaken. This use of a fixed-width type makes your code less portable. However, this mistake is unlikely to cause a problem so long as you work with the widely-available 32 and 64 bit platforms.

As I recall, C requires main() to return int or void. If main() takes any arguments, argc must be an int.

On UNIX and Windows NT, on both 32-bit and 64-bit platforms, the data models specify a 32 bit int. On such platforms, int32_t is implemented using a typedef (or two) which essentially aliases int32_t to int, which is what the standard requires. So long as this is the case, the compiler is happy.

But, what would happen if you tried to compile that on a 16 bit machine? On a 16 bit machine, int32_t may be implemented with long. If that's the case, your code won't compile (if it does, there will likely be serious problems). A similar problem could arise if this code were compiled on a 64 bit architecture with 64 bit ints.

Regards,
Alister
This User Gave Thanks to alister For This Post:
 

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

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

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

5. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

6. UNIX for Dummies Questions & Answers

Segmentation fault

#include<stdio.h> #include<malloc.h> #include<unistd.h> #include<stdlib.h> void *start_1(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); pthread_exit((void*)1); } void *start_2(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); return (void*)2; }... (2 Replies)
Discussion started by: vincent__tse
2 Replies

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

8. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

9. Shell Programming and Scripting

Count Segmentation fault and write to the file

Hi everyone Need to get version of npm application that have several output like this: root: nmp -version 10 root: nmp -version 10 root: nmp-new -version 3.1 root: nmp-old -version Segmentation fault count them , after that write to the file like this: 10 2 3.1 1 (1 Reply)
Discussion started by: indeed_1
1 Replies

10. 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
ATOMIC_ADD(3)						   BSD Library Functions Manual 					     ATOMIC_ADD(3)

NAME
atomic_add, atomic_add_32, atomic_add_int, atomic_add_long, atomic_add_ptr, atomic_add_64, atomic_add_32_nv, atomic_add_int_nv, atomic_add_long_nv, atomic_add_ptr_nv, atomic_add_64_nv -- atomic add operations SYNOPSIS
#include <sys/atomic.h> void atomic_add_32(volatile uint32_t *ptr, int32_t delta); void atomic_add_int(volatile unsigned int *ptr, int delta); void atomic_add_long(volatile unsigned long *ptr, long delta); void atomic_add_ptr(volatile void *ptr, ssize_t delta); void atomic_add_64(volatile uint64_t *ptr, int64_t delta); uint32_t atomic_add_32_nv(volatile uint32_t *ptr, int32_t delta); unsigned int atomic_add_int_nv(volatile unsigned int *ptr, int delta); unsigned long atomic_add_long_nv(volatile unsigned long *ptr, long delta); void * atomic_add_ptr_nv(volatile void *ptr, ssize_t delta); uint64_t atomic_add_64_nv(volatile uint64_t *ptr, int64_t delta); DESCRIPTION
The atomic_add family of functions add a signed value delta to the variable referenced by ptr in an atomic fashion. The *_nv() variants of these functions return the new value. The 64-bit variants of these functions are available only on platforms that can support atomic 64-bit memory access. Applications can check for the availability of 64-bit atomic memory operations by testing if the pre-processor macro __HAVE_ATOMIC64_OPS is defined. SEE ALSO
atomic_ops(3) HISTORY
The atomic_add functions first appeared in NetBSD 5.0. BSD
April 11, 2007 BSD
All times are GMT -4. The time now is 02:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy