May 7, 2018 01:19 PM
(This post was last modified: May 7, 2018 01:20 PM by maryous.)
(May 7, 2018 01:00 PM)Gorzoid Wrote: OP simply changing compiler is not the solution. you need to be aware of const correctness, your lucky the compiler caught you out on this, otherwise you'd have alot of problems in the future when you try to write to readonly memory.
Yeah i read that and i decided to work on virtual windows cuz im new to Malware coding
(May 7, 2018 12:36 PM)Annabelle Lee Wrote: If you are using VS2017, make sure your file ends with .c, and not .cpp
Yeah I did and it worked thanks a lot
(May 7, 2018 09:39 AM)0xDEAD10CC Wrote: Are you sure you're not compiling as C++? That's the issue that nobody has really caught here. You may be trying to write C code, but you're definitely not invoking the C compiler...
Btw, that code should be valid C, but it's a very stupid thing to do. Assigning a literal like "testing" to a char pointer means that you can write code to modify that string, but it won't warn you about the fact that it can't actually do it. You're getting a non-const pointer to read only memory.
Thanks a lot... that solved my issue and as i said i didn't really know there was a difference
I thought the compiler would know by the way you write your main function
May 8, 2018 07:57 PM
(This post was last modified: May 8, 2018 08:00 PM by 0xDEAD10CC.)
(May 7, 2018 01:00 PM)Gorzoid Wrote: OP simply changing compiler is not the solution. you need to be aware of const correctness, your lucky the compiler caught you out on this, otherwise you'd have alot of problems in the future when you try to write to readonly memory.
It is the solution to get that code to compile because it is valid C. Nobody said it was a good thing to do, but C++ is a bit more strict with certain things and even casting when it comes to void pointers. At the end of the day, he was trying to write C code, not C++ code, so taking that into consideration he shouldn't be continuing with the C++ compiler anyways. Const correctness is part of the problem and so is the compiler.
OP - There's a flag with the compiler used by Visual studio that can force a language specific compiler but by default it is based on the filetypes.
(May 8, 2018 07:57 PM)0xDEAD10CC Wrote: It is the solution to get that code to compile because it is valid C. Nobody said it was a good thing to do, but C++ is a bit more strict with certain things and even casting when it comes to void pointers. At the end of the day, he was trying to write C code, not C++ code, so taking that into consideration he shouldn't be continuing with the C++ compiler anyways. Const correctness is part of the problem and so is the compiler.
OP - There's a flag with the compiler used by Visual studio that can force a language specific compiler but by default it is based on the filetypes.
OP never indicated whether he wanted to write C/C++. If he did intend to write cpp then our solution was basically "don't use c++", if he intended to use C one should still have const-correct code.
(May 9, 2018 11:03 AM)Gorzoid Wrote: OP never indicated whether he wanted to write C/C++. If he did intend to write cpp then our solution was basically "don't use c++", if he intended to use C one should still have const-correct code.
yeah my bad, i didn't know there was a difference. I thought the compiler can tell without us adding CPP or C
May 9, 2018 06:07 PM
(This post was last modified: May 9, 2018 06:09 PM by 0xDEAD10CC.)
(May 9, 2018 11:03 AM)Gorzoid Wrote: OP never indicated whether he wanted to write C/C++. If he did intend to write cpp then our solution was basically "don't use c++", if he intended to use C one should still have const-correct code.
That's my point - it is a two part solution to his question since the details were left out. If he wanted that code to compile unmodified, then the answer is to use the C compiler (I already hinted at the fact that I didn't agree with the neglect towards the const qualifier keep in mind).
If he was intending to write C++ code, then maybe using standard C++ headers over ones from the C standard library would be a start to indicate such a thing to any code readers, in addition to using const (regardless of whether he was using C or C++). When I first read it though, that looked like strictly C code to me, and since there was nothing to indicate that it was C++, even after reading the statements he made outside of the code in this thread, I assumed C.
|