Pavel
Definitely 1. Static one have static storage duration 2. Static one will be initialized with a mutex lock
In which memory a usual const can reside? Or that's implementation details?
z
void func() { const int someVar = 20; ... }
Interesting... Let me try to see the compilation output. Wait...
z
void func() { const int someVar = 20; ... }
This the result... extern int test; void func1() { const int someVar = 0xffff; test = someVar; } void func2() { static const int someVar = 0xffff; test = someVar; } func1 stores someVar on the stack. func2 stores someVar on .rodata section. See also: https://godbolt.org/z/8Mn3eW Look at that RIP relative addressing to access the static const int someVar.
z
Data on the stack is always writeable. While .rodata is not writetable. Local variable const int someVar is semantically read only, but at runtime it is actually on the stack. .rodata will not be writable at runtime at all, trying to write to .rodata will result in segmentation fault.
Igor🇺🇦
In which memory a usual const can reside? Or that's implementation details?
Regular function const is the same as any other variable. It's "const" only for type checking.
Pavel
I mean it should be stored somewhere, right?
z
But what about the value it initialized with (0xffff), is it included in the assembly operation?
Yes, in the Assembly operation after function prologue. movl $0xffff,-0x4(%rbp) Note: %rbp is the stack frame pointer. But sections like .text, .data, .rodata do not require instruction for initialization. It is directly mapped to virtual memory when the program gets executed by execve syscall.
Pavel
Cool! Thank you @Mysticial, @unterumarmung, @JRandomGuy
Kelvin
/get
Pavel
How do you decide which types you pass by value and which by reference? If we're talking about trivially copyable structs for example. How small should it be to start considering passing it by value?
Alex
https://stackoverflow.com/questions/30980759/when-should-i-pass-or-return-a-struct-by-value/30981026
Pavel
good reading, thanks
@𝑺𝒐𝒃𝒌𝒂
Hi Need a book for Qt5 gui in C++. Can anyone help?
Karim-
Somebody can help me?
Avique
I am having a problem with a basic C++. I have searched around, but i only found reasons pretty different from what my code is. The gcc error message is: t.cpp:15:5: error: expected unqualified-id before ‘{’ token file t.cpp is: #include <iostream> #include <cstdlib> using namespace std; #include "t.h" class Agent { public: enum e { a,b,c,d }; int z[16]; int n; Agent { int i; for( i=0; i<16; i++) z[i] = 0; } }; file t.h is: #ifndef tH #define tH #endif I would just paste a picture of both files together in a window, small image... for me, that would be better because it has syntax highlighting - but the rules... So, what is wrong with my code? I tried to do changes with it, but this error never disappeared, except when something i know is wrong was written. What is missing or wrong in the class constructor? What is an "unqualified-id"?
Karim-
This calendar software/program should include of the following functions: (1) Output the current date; (2) Output the current year is a leap year or not; (3) Output the specified date is a holiday or not, if it is, printing the holiday name; (4) Output the date of the specified date after n (n>0 and n denotes a integer) days; (5) Output the week No. of the current data in this year. I don't understand 😭😭😭😭
Diego
Good luck
Anonymous
https://github.com/scivey/langdetectpp use this lib
After I cloned on ubuntu, the external folder of this repository was empty, so the make failed and it prompted the lack of dependent files. How to solve this
Alfredo
After I cloned on ubuntu, the external folder of this repository was empty, so the make failed and it prompted the lack of dependent files. How to solve this
It uses submodules, so you need to download them git submodule update --init https://git-scm.com/docs/git-submodule
Anonymous
fatal error: folly/Format.h: No such file or directory #include <folly/Format.h> ^~~~~~~~~~~~~~~~ compilation terminated. CMakeFiles/langdetectpp.dir/build.make:86: recipe for target 'CMakeFiles/langdetectpp.dir/src/Detector.cpp.o' failed
ㅤㅤㅤ
int main() { int m[5][5]= {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0} }; cout<<m[5][5]; return 0; } what's my error
ㅤㅤㅤ
You should use a for loop to print the elements
if I have different elements how can I swap rows
ㅤㅤㅤ
There are many ways
can you tell me or just share the link of tutorial
S__R
can you tell me or just share the link of tutorial
You should try first make you array small and try to swap 2 2 matrix
Anonymous
Hi
Anonymous
I want to c language pdf
Anonymous
Anyone send me
Diego
/get cbook
Diego
Anyone send me
The rules also say you can't ask for PDFs, you've gotta find them yourself
yue
😏
Anonymous
Ok
KIBUTI BOT
Any pdf with solved problems ,c programing plz
Manish
Hi, want to return a unique ptr without transferring the ownership. Caller method should able to perform manipulation on object content by unique ptr. How define such method? Help appreciated
Manish
It should be own by class in which I would like define it.
Santhu
Can any body explain program about implement of emi calculator
olli
It should be own by class in which I would like define it.
but why do you return it then? and how? because the following fails to compile struct Foo { std::unique_ptr<int> Ptr; Foo(int Val) : Ptr(std::make_unique<int>(Val)) {} std::unique_ptr<int> Bar() { return this->Ptr; } }; <source>:11:16: error: call to deleted constructor of 'std::unique_ptr<int>' return this->Ptr;
Vlaspet
Hi, how are you??
Jalal
Hello, I have a .nsi file and I want to check if a font is already installed. How can I do it?
Renuga
#include <stdio.h> #include <conio.h> #include <string.h> void bubbleSort(char [],int); void exchange(char [],int,int); void main() { int x=11; char word[12]="THISISATEST"; printf("\nDescending unSorted:%s", word); bubbleSort(word,x); printf("\nDescending Sorted : %s", word); getch(); return 0; } void bubbleSort(char array[],int arraySize) { int i,j; for(i=0;i<arraySize-1;++i) { for(j=i+1; j<arraySize; ++j) { if(array[i]<array[j]) { exchange(array, i, j); } } printf("\nIteration %d Sorted : %s",i+1,array); } } void exchange(char array[],int index1,int index2) { char temp; temp=array[index1]; array[index1]=array[index2]; array[index2]=temp; }
Renuga
this bubble sort is giving this output Descending unSorted:THISISATEST Iteration 1 Sorted : THISISATEST Iteration 2 Sorted : TTHIISASEST Iteration 3 Sorted : TTTHIIASESS Iteration 4 Sorted : TTTSHIAIESS Iteration 5 Sorted : TTTSSHAIEIS Iteration 6 Sorted : TTTSSSAHEII Iteration 7 Sorted : TTTSSSIAEHI Iteration 8 Sorted : TTTSSSIIAEH Iteration 9 Sorted : TTTSSSIIHAE Iteration 10 Sorted : TTTSSSIIHEA Descending Sorted : TTTSSSIIHEA
Renuga
BUT I SHOULD GET THIS OUTPUT Descending unSorted : THISISATEST Sorted : TTHISISATES Sorted : TTTHISISASE Sorted : TTTSHISISAE Sorted : TTTSSHISIEA Sorted : TTTSSSHIIEA Sorted : TTTSSSIHIEA Sorted : TTTSSSIIHEA Sorted : TTTSSSIIHEA Sorted : TTTSSSIIHEA Descending Sorted : TTTSSSIIHEA
Renuga
WHAT IS WRONG IN MY CODES?
Nils
WHAT IS WRONG IN MY CODES?
Pls use pastebin or any other similar service and ALSO PLEASE DON'T SCREAM
Anonymous
#include <stdio.h> #include <conio.h> #include <string.h> void bubbleSort(char [],int); void exchange(char [],int,int); void main() { int x=11; char word[12]="THISISATEST"; printf("\nDescending unSorted:%s", word); bubbleSort(word,x); printf("\nDescending Sorted : %s", word); getch(); return 0; } void bubbleSort(char array[],int arraySize) { int i,j; for(i=0;i<arraySize-1;++i) { for(j=i+1; j<arraySize; ++j) { if(array[i]<array[j]) { exchange(array, i, j); } } printf("\nIteration %d Sorted : %s",i+1,array); } } void exchange(char array[],int index1,int index2) { char temp; temp=array[index1]; array[index1]=array[index2]; array[index2]=temp; }
#include <stdio.h> #include <string.h> #define SWP(a, b) do { int _SWP = (a); (a) = (b); (b) = _SWP; } while(0) #define BUBBLE(a, cmp, b) if((a) cmp (b)) { SWP(a, b); done = 0; } int main() { char data[128]; // prevent read-only me ory error, int len, done; // or use "-fwritable-strings" flag sprintf(data, "THISISATEST"); len = strlen(data); printf("\n\nforward sorting: '%s'\n\n", data); do { done = 1; for(int i = 1; i < len; i++) BUBBLE(data[i-1], >, data[i]); printf(" %s\n", data); } while(!done); // sprintf(data, "THISISATEST"); len = strlen(data); printf("\n\nbackward sorting: '%s'\n\n", data); do { done = 1; for(int i = 1; i < len; i++) BUBBLE(data[i-1], <, data[i]); printf(" %s\n", data); } while(!done); return 0; }
Renuga
thank you
Anonymous
Notice how an a high or low value can get moved multiple times in the same sweep.
World Stream
Did any interested to learn C Programming full course for free
World Stream
DM me
Aaditya
DM me
I am block
World Stream
/admin
klimi
Aaditya
/admin
Will u teach me c programming
World Stream
Can I send a c programming tutorial link in your group
Roxifλsz 🇱🇹
Can I send a c programming tutorial link in your group
If it's not just an advertisement for some product, sure
Anonymous
Normally people put links in profile Bio...
World Stream
Check my bio
Anonymous
Check my bio
This is getting a little off-topic... You would fit in better over at the "Cwithme" Telegram group.
Anonymous
hehe
Evil grin
Anyone here familiar with global gnu