Anonymous
And also you probably need to pass an adress of the function (e.g. &compare)
&compare is in most contexts the same as compare as function names decay to pointers to functions automatically
Anonymous
Any groups or channels focused on SDL2?
Anonymous
Any groups or channels focused on SDL2?
I don't know about telegram but there's one on discord
Anonymous
I don't know about telegram but there's one on discord
They have a C++ community there as well and on Slack too. They have different channels for people based on their proficiency and the discussions are great. Most people are migrating from Reddit to those 2.
Anonymous
One Tech Limited is a company that deals with the sale of computer accessories. The company has FOUR (4) branches that are open for SIX (6) days in a week. Write a program using a nested loop that captures sales by the branches in each of the working days. Your program should then compute average sale for each branch and Total sale made by the company. Ensure you solution adheres to coding standard key among them use of comments, indentation and naming of identifiers.
Anonymous
Help me out please guys
Anonymous
Hello
Paul
Help me out please guys
First write out your own idea and then ask for help
Amine
pls who now about desktop application programming by C++ (full app ) anyone has idea about it !!
Frimpomaa
Plz i hv a problem in c and the problem is : Double problem(double Num, double Memo ) { If ( Memo[Num] != NULL) {return Result = 1} } And is not working
Anonymous
if my window is 400 by 400, and im drawing to 200 by 200, and my clip is 100 by 100, then my transformed clip is 100 by 100 right? if so, if i change my clip to 110 by 110, then my transformed clip should be 110 by 110 right? as for me it is 220 by 220 https://gist.github.com/mgood7123/4e5db735f8cd27861594884d2c0fcb67
Shvmtz
In C, the string literal ("Hello") is located in which memory if used as such: char* str = "Hello"; or char str[] = "Hello";
Shvmtz
In first case it'll be in .data section. In second one it'll get copied to stack.
Since the string literal "Hello" is just an array of characters. Does this string literal itself i.e. "Hello" come from the stack memory ??
Nils
If you store it in an array it'll be on stack, if you store the pointer to it it'll be in .data
Anonymous
in Java, all string literals are stored in a pool and referenced to avoid duplicates 🙂
Anonymous
eg str1 = "hi"; // stored in pool because it does not yet exist str2 = "hi"; // found in pool and used as ref, i assume this will be copied/duplicated on modification
Nils
In fact, old GCC did copy on write like java
Anonymous
:)
Anonymous
yup
Anonymous
i do not know if obj("foo"); will store "foo" in a pool or just use it as a temporary object
Anonymous
C/c++ do the same ?
depends on the compiler and implementation
Anonymous
but probably yes
Shvmtz
i do not know if obj("foo"); will store "foo" in a pool or just use it as a temporary object
I guess... Since "foo" is just a character array with null termination. So, maybe it will decay to char* if passed to obj()
Shvmtz
in C/C++ ?
Anonymous
yes
Nils
C/c++ do the same ?
char str[] = "Hello" Copies into stack char *str = "Hello" char *str2 = "Hello" References from 2 different locations in .data section puts("Hello"); References from .rodata section since puts() accepts a const char* const char *str = "Hello" and const char *str2 = "Hello" as well as puts("Hello") References from the same location in .rodata
Nils
But it might be implementation defined.
Anonymous
yea
Shvmtz
I think it depends. If the literal is assigned to a char* then ptrA and ptrB will point to same memory. And if the literal is assigned to char[] then ptrA and ptrB will point to different memory.
Ehsan
They are different in .data section, here is an article about all the data segments: https://www.wikiwand.com/en/Data_segment
Anonymous
if it is assigned to const char * then it will likely point to the same location somewhere for optimization reasons eg you dont want a million read-only strings that ALL containing the exact same string const char * PTR_A = \ "hello" / const char * PTR_B = otherwise with char * it will be copied somwhere suitible for modification this WILL have a million read/write strings that MIGHT ALL contain the exact same string char * PTR_A = \ "hello" char * PTR_B = \ "hello"
Nils
Okay. Got it. Thanks
It simply does several push instructions 😉 In fact, "Hello" requires just 1 push instruction. The entire string can be fit into a single 64bit integer.
Anonymous
ALSO const char * PTR_A = \ "hello" / const char * PTR_B = char * PTR_C = strdup(PTR_B) <assigning string literal to 'char*' is not allowed> \ "hello" <ALLOCATED COPY, MUST BE FREED>
Anonymous
Nils
Actually modifying the string then is UB.
Nils
Nothing special. You will get a compiler warning. And writing to v dereference will be undefined behavior.
Anonymous
yea
Anonymous
this IS allowed tho const char * v = nullptr; void set(const char * val) { v = val; } int main() { set("hi"); const char * x = "foo"; set(x); return 0; } since it is only modifying pointer's and not contents
Anonymous
Heyy you all
Nils
this IS allowed tho const char * v = nullptr; void set(const char * val) { v = val; } int main() { set("hi"); const char * x = "foo"; set(x); return 0; } since it is only modifying pointer's and not contents
const char * v = nullptr; void set(const char * val) { v = val; } void function() { set("hi"); const char x[] = "foo"; set(x); return 0; } This in turn would cause a dangling reference after function() returns.
Anonymous
yup
Anonymous
since x goes out of scope and it is not allocated, and is also an array instead of a pointer, so all characters are copied into it
Nils
Because then the string is stored in .rodata instead of stack
Anonymous
i prefer set("foo") instead as it is more clear 🙂
Ehsan
In C, the string literal ("Hello") is located in which memory if used as such: char* str = "Hello"; or char str[] = "Hello";
The first one is a string literal that is stored in the data section(read-only data section specifically) While the other one is stored in the stack
Ehsan
For this code: ``` #include <stdio.h> int main() { char s[] = "I am in the stack ;)"; char* d = "I am hard coded +_+"; return 0; } ``` The data section is: ```Contents of section .rodata: 0000 4920616d 20686172 6420636f 64656420 I am hard coded 0010 2b5f2b00 +_+.```
Ehsan
It doesn’t matter if you put const before the pointer
Ehsan
the const is just to make sure that the data will not be changed
Ehsan
That is why its always adviced to use: const char* x instead of char* x so you can detect problems at compile time. The string literal is in read-only section and mustn't be tampered with during program execution.