const-char

How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC?

So I'm working on an exceedingly large codebase, and recently upgraded to gcc 4.3, which now triggers this warning: warning: deprecated conversion from string constant to ‘char*’ Obviously, the correct way to fix this is to find every declaration like char *s = "constant string"; or function call like void foo(char *s); foo...

How come XDrawString doesn't take "const char *"?

Hi, looking at the declaration for XDrawString from X11, it is int XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, int length); How come the 6th argument is type "char *" instead of "const char *"? Does drawing the string require modifying it? I've seen lots of examples where people pass in...

Are strtol, strtod unsafe?

It seems that strtol() and strtod() effectively allow (and force) you to cast away constness in a string: #include <stdlib.h> #include <stdio.h> int main() { const char *foo = "Hello, world!"; char *bar; strtol(foo, &bar, 10); // or strtod(foo, &bar); printf("%d\n", foo == bar); // prints "1"! they're equal *bar = 'X'; // seg...

printf question with a const char* variable

Hi, I am stuck in a printf problem. I would appreciate if I can get some help here: In the below code, I can see the font family get displaced correctly in first printf(), but if I set it to variable, i only get an empty string. How can I put it in a variable and have the right values? I just don't want to type 'font.family().family().s...

Python to C/C++ const char question

I am extending Python with some C++ code. One of the functions I'm using has the following signature: int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, char *format, char **kwlist, ...); (link: http://docs.python.org/release/1.5.2p2/ext/parseTupleAndKeywords.html) The parameter of inter...

std::cin >> *aa results in a bus error

I have this a class called PPString: PPString.h #ifndef __CPP_PPString #define __CPP_PPString #include "PPObject.h" class PPString : public PPObject { char *stringValue[]; public: char *pointerToCharString(); void setCharString(char *charString[]); void setCharString(const char charString[]); }; #endif PPString.cpp...

How do I properly turn a const char* returned from a function into a const char** in C?

In short, I would like to do this: const char **stringPtr = &getString(); However, I understand that you can't & on rvalues. So I'm stuck with this: const char *string = getString(); const char **stringPtr = &string; I can live with two lines. Am I introducing problems with this hack? I should have no fear of passing stringPtr out ...

Is it appropriate to set a value to a "const char *" in the header file

I have seen people using 2 methods to declare and define char * Medhod-1: The header file has the below extern const char* COUNTRY_NAME_USA = "USA"; Medhod-2: The header file has the below declaration extern const char* COUNTRY_NAME_USA; The cpp file has the below defintion : extern const char* COUNTRY_NAME_U...