Sponsored Content
Top Forums Programming C++ program is crashing on re-assigning const static member variable using an int pointer Post 302489053 by Corona688 on Wednesday 19th of January 2011 10:56:08 AM
Old 01-19-2011
Global constants get hardware write-protection on lots of OSes. The program literally cannot write to them, memory map settings prevent it, the CPU itself knows you shouldn't and throws an exception if you try.

A static variable is as good as a global variable in most respects, this included.

Trying to get around this with trickery isn't a good idea. Even if you alter page protection to let you write, the program might ignore it when you do! The compiler, knowing the variable is a constant, will think "hmm, this variable will never change -- I can save 2 instructions per go by hardcoding it everywhere instead of reading it from memory..."
 

10 More Discussions You Might Find Interesting

1. Programming

Accesing structure member:Error:dereferencing pointer to incomplete type

$ gcc -Wall -Werror struct.c struct.c: In function `main': struct.c:18: error: dereferencing pointer to incomplete type $ cat struct.c #include <stdio.h> #include <stdlib.h> #include <string.h> /*Declaration of structure*/ struct human { char *first; char gender; int age; } man,... (3 Replies)
Discussion started by: amit4g
3 Replies

2. UNIX for Dummies Questions & Answers

int open(const char *pathname, int flags, mode_t mode) doubt...

hello everybody! I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(){ int fileDescriptor; fileDescriptor =... (2 Replies)
Discussion started by: csnmgeek
2 Replies

3. Solaris

Assigning a static IP to NICs

Hi, I have checked the net and can't find why I can't ping the server nor can I ping any address inside or outside the network from the server (using serial connection). I can set up DHCP on the server and it gets an address of 192.168.1.118 and everything is fine. I cannot ping anything from... (10 Replies)
Discussion started by: sunfan
10 Replies

4. Red Hat

cast from const void* to unsigned int loses precision

Hello everey one, here i am attempting to compile a c++ project .it's throughing the following errors. my machine details are as follows: Linux chmclozr0119 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux errors: ===== Generating... (0 Replies)
Discussion started by: mannam srinivas
0 Replies

5. Programming

tolower (static pointer + malloc + realloc)

N00B here. This function would be easier using a char pointer along with free. But I wish to learn how to use char static pointers (they do not require free, right ?). How do I erase the content of a static pointer ? Terminating the string works but the static pointer's content is not being... (4 Replies)
Discussion started by: limmer
4 Replies

6. Programming

C++ type-casting a member variable in const methods

Is it permitted to type-cast a member variable passed in as a parameter in a member const method .. I am doing something like : in a return-type method () const { variable other = long(member variable) } this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies

7. Programming

Handle int listen(int sockfd, int backlog) in TCP

Hi, from the manual listen(2): listen for connections on socket - Linux man page It has a parameter called backlog and it limits the maximum length of queue of pending list. If I set backlog to 128, is it means no more than 128 packets can be handled by server? If I have three... (3 Replies)
Discussion started by: sehang
3 Replies

8. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

9. Programming

Why this C program is crashing?

Hi, Why I am getting 'SIGSEGV' in the following code? char* p="abcde"; printf("%s", 3); // Segmentation Fault (core dump) Kindly help me to understand what exactly makes the program to crash or the reason for the crashing. (7 Replies)
Discussion started by: royalibrahim
7 Replies

10. Programming

Declare member of struct as a pointer in c

I have a uint8_t *C = malloc(24*sizeof(uint8_t)); I need to send some integers and this *C to another node(in ad hoc network). So I am going to use a struct ` struct fulMsg { int msgType; int msgCount; //uint8_t *CC; } fulMsg_t; typedef struct fulMsg fulMsg_tt;` there is a method... (1 Reply)
Discussion started by: chap
1 Replies
SUBPAGE_PROT(2) 					     Linux Programmer's Manual						   SUBPAGE_PROT(2)

NAME
subpage_prot - define a subpage protection for an address range SYNOPSIS
long subpage_prot(unsigned long addr, unsigned long len, uint32_t *map); Note: There is no glibc wrapper for this system call; see NOTES. DESCRIPTION
The PowerPC-specific subpage_prot() system call provides the facility to control the access permissions on individual 4 kB subpages on sys- tems configured with a page size of 64 kB. The protection map is applied to the memory pages in the region starting at addr and continuing for len bytes. Both of these arguments must be aligned to a 64-kB boundary. The protection map is specified in the buffer pointed to by map. The map has 2 bits per 4 kB subpage; thus each 32-bit word specifies the protections of 16 4 kB subpages inside a 64 kB page (so, the number of 32-bit words pointed to by map should equate to the number of 64-kB pages specified by len). Each 2-bit field in the protection map is either 0 to allow any access, 1 to prevent writes, or 2 or 3 to prevent all accesses. RETURN VALUE
On success, subpage_prot() returns 0. Otherwise, one of the error codes specified below is returned. ERRORS
EFAULT The buffer referred to by map is not accessible. EINVAL The addr or len arguments are incorrect. Both of these arguments must be aligned to a multiple of the system page size, and they must not refer to a region outside of the address space of the process or to a region that consists of huge pages. ENOMEM Out of memory. VERSIONS
This system call is provided on the PowerPC architecture since Linux 2.6.25. The system call is provided only if the kernel is configured with CONFIG_PPC_64K_PAGES. No library support is provided. CONFORMING TO
This system call is Linux-specific. NOTES
Glibc does not provide a wrapper for this system call; call it using syscall(2). Normal page protections (at the 64-kB page level) also apply; the subpage protection mechanism is an additional constraint, so putting 0 in a 2-bit field won't allow writes to a page that is otherwise write-protected. Rationale This system call is provided to assist writing emulators that operate using 64-kB pages on PowerPC systems. When emulating systems such as x86, which uses a smaller page size, the emulator can no longer use the memory-management unit (MMU) and normal system calls for control- ling page protections. (The emulator could emulate the MMU by checking and possibly remapping the address for each memory access in soft- ware, but that is slow.) The idea is that the emulator supplies an array of protection masks to apply to a specified range of virtual addresses. These masks are applied at the level where hardware page-table entries (PTEs) are inserted into the hardware page table based on the Linux PTEs, so the Linux PTEs are not affected. Implicit in this is that the regions of the address space that are protected are switched to use 4-kB hardware pages rather than 64-kB hardware pages (on machines with hardware 64-kB page support). SEE ALSO
mprotect(2), syscall(2) Documentation/vm/hugetlbpage.txt in the Linux kernel source tree COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 SUBPAGE_PROT(2)
All times are GMT -4. The time now is 07:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy