Earn money with programming

Pages: 1... 567
compilers cannot make any assumptions basing on declared constness


1
2
3
4
5
const int x = 10;
const int* y = &x;
*const_cast<int*>(y) = 20;
std::cout<<x<<std::endl;
std::cin.get();


10
closed account (EzwRko23)
@up: ok, I agree, they can - creating undefined behavior as a side effect. What I wanted to say is they cannot make **safe** assumptions basing on declared constness. They actually use it, but they may change program semantics (ok, just as many other optimizations, like RVO, which also may change semantics of a correct program - that is why in C++ it is so often that in release mode your program crashes and when you try to debug it, everything works perfectly).

But even without casting you can easily break constness:

1
2
3
4
5
6
7
void update(char* y) {
  y[0] = 'z';
}

int main() {  
  update("a");
}


Compile error? No. Segmantation fault.

Last edited on
The above is not C++
From the ISO document ( § 2.13.4 ) :
An ordinary string literal has type “array of n const char”

G++ gives the warning: deprecated conversion from string constant to ‘char*’
closed account (EzwRko23)
But it compiles. Conversion from string constant to char* is only warned about but allowed by the standard.
Last edited on
That's because it's deprecated and not illegal.
The 2003 standard paper is quite clear when it says An ordinary string literal has type “array of n const char”
If g++ decides to compile anyways is not the standards' fault.
( if you compile with the -Werror flag it will give an error and won't compile )
closed account (z05DSL3A)
But it compiles. Conversion from string constant to char* is only warned about but allowed by the standard.
So what is at fault here, the language or the implementation of the compiler?
Last edited on
So what is at fault here, the language or the implementation of the compiler?
The C89 standard. I mean, why would you put string literals in read-only memory if you'll allow the programmer at compile time to write to them?
Last edited on
You probably should just sell your games on a website. You can code your website, but if you're lazy like me, just make a site on weebly or something.
closed account (EzwRko23)
Most of such games don't earn more than $20 / month or so. Only few great games make serious money for their authors.
closed account (z05DSL3A)
So what is at fault here, ...
The C89 standard. ...

but the standard is what the standard is. At the time enough people thought that it was a sensible solution to a problem to be standardised . Now, by the fact that it is deprecated, suggests that there is another way of dealing with the issue or that they don't agree with it but have not found a way around it yet (depending on how long it has been deprecated).

But anyway it was a bit of a loaded question. If you don't believe that the implicit conversion of a string literate to a pointer to a char array is a problem then you are fine because the current standard allows it. However, if you believe it to be wrong, then the current standard agrees with you as it is deprecated.

NB: I hold no strong views either way on the correctness of this issue.
I believe C++ is still needed in very low level programming tasks. E.g company that sell C++ compiler, company that sell Java Virtual Machine, company that build server software (infrastructure plumbing code) etc etc but those positions will be much lesser compared to say Java.

The reason is simple, there are MORE applications that need to be developed for businesses. Do we have thousands of company that sell C++ compiler, Java Virtual Machine etc ? What I know is we have thousands of company that sell applications instead.

As to the pay discrepancy, I would feel C++ would command higher as the pool is smaller and the position are usually very specialized. But this also mean if you are a C++ developer, you have less positions to apply jobs for in comparison to Java where positions are in abundance.

I believe if a developer can do BOTH Java C++ and other languages, he will be value for money to the employer. Of cuz some employers still feel Jack of all trades is no good compared to a person who specialized in only a specific language. This is perception which I cannot comment.

To go to something metioned a few pages ago, but that I feel compelled to correct: Fortran is a *programming language*, not a platform. It is used mainly used in the problem domain of scientific computing, but is being taken over fairly rapidly by C++ in this arena as less and less people are trained in it's use, and compiler support for modern systems becomes less and less.

More on topic: I tried freelancing for a short time on similar sites (some time ago now) to those mentioned previously (rentacoder I think I looked at), with little success. The people who post adds on such job boards tend to not know what they want, so you'll often end up putting far more work in than you should for the price you agreed to. If you want to make money, keep practicing and find a proper, salaried job. C++ knowledge is still very much in demand.

Re: previous post, I feel that if someone has a dozen technologies listed on their resume (say C++, Python, Java, PHP, etc), then people are obviously going to take the impression that they haven't done much interesting with any of them. Better to really know one language, and from that have learnt the processes of software development that you can apply everywhere, than to learn how to say Hello World in every language ever conceived.
Topic archived. No new replies allowed.
Pages: 1... 567