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