Anshul
Anonymous
Any groups or channels focused on SDL2?
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
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";
Nils
Nils
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
Shvmtz
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
Shvmtz
Nils
Nils
In fact, old GCC did copy on write like java
Anonymous
:)
Shvmtz
Anonymous
yup
Shvmtz
Anonymous
i do not know if obj("foo"); will store "foo" in a pool or just use it as a temporary object
Anonymous
but probably yes
Shvmtz
Nils
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
Shvmtz
Nils
Shvmtz
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.
Nils
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>
Shvmtz
Nils
Shvmtz
Anonymous
Shvmtz
Nils
Nils
Actually modifying the string then is UB.
Anonymous
Shvmtz
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
Nils
Anonymous
Heyy you all
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
Shvmtz
Shvmtz
Nils
Nils
Because then the string is stored in .rodata instead of stack
Shvmtz
Anonymous
i prefer set("foo") instead as it is more clear 🙂
Ehsan
Ehsan
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.
Shvmtz
Ehsan
Shvmtz
Shvmtz