Ehsan
Btw how did you get the contents of data section ?
In linux: First you generate the object file: gcc -c file.c then use objdump to extract the object file’s section: objdump -s file.o also you can read the manual if you need something else
Anonymous
#include <stdio.h> #include <stdlib.h> int main() { int x; for(x=10;x>=1;x--) printf("%d ",x); return 0; } ——————————————— #include <stdio.h> #include <stdlib.h> int main() { int x; for(x=10;x>=1;x--) printf("%d ",&x); return 0; } ———————————————-- Anyone can explain about these 2 codes? what & do in printf function?
Thomas shelby
#include<stdio.h> void main() {     int a[6],b[6],c[]={0,0,0,0,0,0,0,0,0,0,0,0},k=6;     printf("enter the numbers in a:");     scanf("%d",&a);     printf("enter the numbers in b:");     scanf("%d",&b);     for(int i=0;i<6;i++)       {c[i] = a[i];       printf("%d",c[i]);}     for(int j=0;j<6;j++)     {         for(int l=0;l<6;l++)         {             if(c[j]!=b[l])             {                 k++;                 c[k]=b[l];             }         }         for(int m=0;m<12;m++)             printf("\n %d",c[m]);     } }
Thomas shelby
I tried to write a code to merge two array and make a new distinct array Can anyone tell me what's wrong with this code
Thomas shelby
👍
Anonymous
Write a C program that consist of structure called student with data members roll,name and GPA .Store the studnet information of 10 studnets and display the record of student in ascending order as per the gpa score.
Good
I am trying to integrate the third-party shared libraries into my build for QEMUx86-64 using yocto.I can able to install the libraries and link them to the application successfully. But now the problem is whiling executing the do_rootfs command I am getting below error.
Good
Error: Problem 1: conflicting requests - nothing provides libc.so.6(GLIBC_2.25) needed by memstack-1.0-r0.core2_64 Problem 2: package mem-manager-1.0-r1.core2_64 requires libmemstack.so.0.1()(64bit), but none of the providers can be installed - conflicting requests - nothing provides libc.so.6(GLIBC_2.25) needed by memstack-1.0-r0.core2_64
Good
I added the DEPENDS on glibc in the respective third-party.bb file. But I am facing the same error, am I missing something here?
Good
third-party.bb file can be found here:https://pastebin.com/rZ6bDAsh
我是大娃
hello bodys, why use malloc > 32MB, cost much more time
我是大娃
----------------------------------------------------- Benchmark Time CPU Iterations ----------------------------------------------------- BM_MORE 4404 ns 4398 ns 159684 BM_LESS 29.0 ns 29.0 ns 24110384
我是大娃
static void BM_MORE(benchmark::State& state) { char *s = nullptr; const long long size = 34000000; for (auto _ : state) { s = (char*)malloc(sizeof(char)*size); free(s); } } BENCHMARK(BM_MORE); static void BM_LESS(benchmark::State& state) { char *s = nullptr; const long long size = 33000000; for (auto _ : state) { s = (char*)malloc(sizeof(char)*size); free(s); } } BENCHMARK(BM_LESS);
klimi
hello bodys, why use malloc > 32MB, cost much more time
probably because there are few big spots left in memory whereas when you need smaller chunk, the probability is much higher
ʟᴏɴᴇᴡᴏʟꜰ
As a beginner in CSE should I start with C or C++ ?
Pavel
As a beginner in CSE should I start with C or C++ ?
If you want to write in C++, then go for C++, if you want to write in C, then learn C. If you don't know, I would suggest C++
ʟᴏɴᴇᴡᴏʟꜰ
Okay
Anonymous
static void BM_MORE(benchmark::State& state) { char *s = nullptr; const long long size = 34000000; for (auto _ : state) { s = (char*)malloc(sizeof(char)*size); free(s); } } BENCHMARK(BM_MORE); static void BM_LESS(benchmark::State& state) { char *s = nullptr; const long long size = 33000000; for (auto _ : state) { s = (char*)malloc(sizeof(char)*size); free(s); } } BENCHMARK(BM_LESS);
It depends on your implementation. If your implementation uses chunks of size say 32 MB (usually it is much lesser), then allocating memory less than 32 MB is equivalent to finding a free chunk in your memory slab. But if you request memory more than 32 MB then it may have to find two contiguous chunks and if you have considerable memory fragmentation (we cant comment on how much fragmentation you have caused because you havent shown us the whole code) then malloc has to work a lot harder to free up two consecutive chunks (by coalescing free chunks) which may cause some slowness.
Hanz
Woah that is understandable out of the box
Sandeep
String ans=""; ans+="-1"; This one gives output as -1 and if I do ans+='-1'; This one gave output 1 How
Anonymous
String ans=""; ans+="-1"; This one gives output as -1 and if I do ans+='-1'; This one gave output 1 How
in the most likely case - '-1' is an int whose value is 0x2D31 (0x2D is ascii for '-' and 0x31 is ascii for '1')
ERROR
Best YouTube channel for learning DSA
Anonymous
Anonymous
So it leaves the 2D part?
depends on whether char is signed. if it is signed, then this is undefined behaviour. if it is unsigned, then yes it just does a % 0x100 which leaves only the 0x31.
Anonymous
undefined behaviour -> compiler writers write compilers assuming the input code never exhibits undefined behaviour. so there is no guarantee what happens when input code does exhibit such behaviour.
Sandeep
depends on whether char is signed. if it is signed, then this is undefined behaviour. if it is unsigned, then yes it just does a % 0x100 which leaves only the 0x31.
If it is unsigned character ..then there will be extra bits for sign...so we don't know what part will be left ..is that it?
Sandeep
> unsigned character > extra bits for sign ?
You said..while converting to char...some bits will be left
Anonymous
You said..while converting to char...some bits will be left
char is an integral type. integral types can either be signed or unsigned. for signed integral types, overflow is undefined. for unsigned integral types, modular arithmetic is used to wrap the value around.
Anonymous
char is an integral type. integral types can either be signed or unsigned. for signed integral types, overflow is undefined. for unsigned integral types, modular arithmetic is used to wrap the value around.
test code #include <iostream> #include <limits> int main() { std::cout << std::numeric_limits<char>::is_signed << '\n'; }
Anonymous
in the most likely case - '-1' is an int whose value is 0x2D31 (0x2D is ascii for '-' and 0x31 is ascii for '1')
It may be 0x312D0000 as well depending on whether the system is big endian or little endian.
J
👍
Subhankar
can i get a help for my tomorrow exam on competitive coding
Anonymous
It may be 0x312D0000 as well depending on whether the system is big endian or little endian.
no. https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=msvc-160#microsoft-specific https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html https://github.com/llvm/llvm-project/blob/main/clang/lib/Lex/LiteralSupport.cpp#L1416
Anonymous
It may be 0x312D0000 as well depending on whether the system is big endian or little endian.
i mean that could be the memory representation, but it is still equal to the number 0x2D31
Anonymous
Ist there any in depth comparison between rust and C++, all i have seen so far seemed shallow. Im struggeling to decide if its worth starting a project in rust when im mainly usually manly a c++ developer
Anonymous
no. https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=msvc-160#microsoft-specific https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html https://github.com/llvm/llvm-project/blob/main/clang/lib/Lex/LiteralSupport.cpp#L1416
I meant to say 0x0000312D but I said 0x312D0000 instead. Yes but you ignored the "this is Microsoft specific" implementation. This need not be the case for all machines. As far as the standard is concerned, it just requires multi character literals to be processed from left to right. There is no standard requirement on how the actual int value is constructed. So '-1' may be stored in memory from low address to high address as 0x2D 0X31. Assuming it is a little endian machine the int value will be 0x312D. The int value need not always be calculated using shifting. The standard leaves that to the implementation. Microsoft does it this way and documents it. It is possible for an implementation to interpret the bytes in memory itself as the int value as long as it documents it. The point here is that the actual int value is implementation specific and need not always be 0x2D31
Anonymous
I meant to say 0x0000312D but I said 0x312D0000 instead. Yes but you ignored the "this is Microsoft specific" implementation. This need not be the case for all machines. As far as the standard is concerned, it just requires multi character literals to be processed from left to right. There is no standard requirement on how the actual int value is constructed. So '-1' may be stored in memory from low address to high address as 0x2D 0X31. Assuming it is a little endian machine the int value will be 0x312D. The int value need not always be calculated using shifting. The standard leaves that to the implementation. Microsoft does it this way and documents it. It is possible for an implementation to interpret the bytes in memory itself as the int value as long as it documents it. The point here is that the actual int value is implementation specific and need not always be 0x2D31
you said "depending on whether the system is big endian or little endian". my "no." in the last message was just that it did not NECESSARILY depend on endianness. i am not arguing that the value is not implementation defined. intel is little-endian and i get 0x2D31 on my PC. gcc, clang, msvc all implement it the same way regardless of endianness. microsoft's special behaviour is that assigning to char and wchar are valid, and L'...' multicharacter literals just take the first character and ignore everything else (no special ints). edit: new text in ALL-CAPS
Anonymous
String ans=""; ans+="-1"; This one gives output as -1 and if I do ans+='-1'; This one gave output 1 How
btw i hope you understood the actual problem. in C/C++ " " and ' ' are not interchangeable. one defines string literals, the other defines character constants, and sometimes (when you try to jam multiple characters in a single ' ') integer constants,
Osama
Hello everyone, I'm developing an ERP system with a team and I've been searching for resources that could help us like ERP for programmers but didn't find any. All of the resources I found is focused on end users. Could someone help me? Thanks in advance.
.
Are there any good performance testing tools that can measure the specific call time of each function?
.
gprof. perf seems to be able to see it, but I want to compare the call time of each function of the two different versions of the program
Anonymous
you said "depending on whether the system is big endian or little endian". my "no." in the last message was just that it did not NECESSARILY depend on endianness. i am not arguing that the value is not implementation defined. intel is little-endian and i get 0x2D31 on my PC. gcc, clang, msvc all implement it the same way regardless of endianness. microsoft's special behaviour is that assigning to char and wchar are valid, and L'...' multicharacter literals just take the first character and ignore everything else (no special ints). edit: new text in ALL-CAPS
Yes it may depend on endianness which can be documented by an implementation as such. You get 0x2d31 on your little endian system because your implementation uses shifting. My point is that shifting isn't always the only way just because MSVC, GCC use that. It would be perfectly valid for an implementation to document that the value of a multi character literal will be based on the endianness of the architecture and could also document which character it stored in the low address and which character in the high address. I am saying this because you said earlier that the multi character literal '-1' can never have the value 0x312d and that it will always be only 0x2d31 My point is that it can have the value 0x312d if the implementation chooses to decide a value based on the endianness of the system. So your saying that it can never depend on endianness is wrong. It can if an implementation chooses to do so which would be perfectly valid Implementation Defined Behavior. Btw multi character literals are only conditionally supported meaning a compiler can even flag them as an error.
Anonymous
Hi
Anonymous
I want to learn c language 🙂
Φ ☭
DEV 7
Why we use auto keyword in c++ with simple example
Nils
Why we use auto keyword in c++ with simple example
std::vector<char> xxx; //... auto iterator = xxx.begin(); The non-auto way would be: std::vector<char>::iterator iterator = xxx.begin();
Anonymous
> It would be perfectly valid for an implementation... yes it would, but > It may be 0x312D0000 0x0000312D as well depending on whether the system is big endian or little endian. this statement is still incorrect. it may definitely be 0x312D, but that value may or may not depend on whether the system is big endian or little endian.
Why? If an implementation decides that a multicharacter literal like '-1' would store '-' in a low byte and '1' in a high byte and then interpret the two bytes as an int using the underlying endianness and padding 0x00 in front why would that not be an implementation dependent Behavior? In other words, the same compiler could interpret 'abcd' as 0x31323334 on one endian system and 0x34333231 on another. This is valid implementation defined Behavior.
Anonymous
Why? If an implementation decides that a multicharacter literal like '-1' would store '-' in a low byte and '1' in a high byte and then interpret the two bytes as an int using the underlying endianness and padding 0x00 in front why would that not be an implementation dependent Behavior? In other words, the same compiler could interpret 'abcd' as 0x31323334 on one endian system and 0x34333231 on another. This is valid implementation defined Behavior.
yes it would be a perfectly valid implementation. however, if an implementation decides that the characters will be parsed right-to-left (instead of left-to-right), shifting left every time a new character is read, then the value is still 0x0000312D. it would still be implementation defined behaviour, but it won't depend on endianness. the shift operator abstracted the endianness it away.
Anonymous
yes it would be a perfectly valid implementation. however, if an implementation decides that the characters will be parsed right-to-left (instead of left-to-right), shifting left every time a new character is read, then the value is still 0x0000312D. it would still be implementation defined behaviour, but it won't depend on endianness. the shift operator abstracted the endianness it away.
No. You are assuming there is a shift operation happening. Read my message above. There is no shift operation there. The compiler just stores the multi character literal in memory and reads the memory as it is to get the int which depends on endianness. In cases where there are less than sizeof(int) characters, the compiler can pad 0s in front. In particular read the example for 'abcd' that I have above.
Anonymous
i am not talking about your hypothetical implementation. i am talking about a different hypothetical implementation to support my claim "it may definitely be 0x312D, but that value (may or) may not depend on whether the system is big endian or little endian."
I am talking about implementation defined Behavior which can very well depend on endianness and is still standard compliant. So your saying that it cannot be determined by endianness is wrong. A simple way to disprove me would be to show that any implementation defined Behavior that takes endianness into account is not correct according to the standard.
Anonymous
@SilhouetteInDark ok i fixed this message
Lol. You dont have to go and change messages in the past. As long as we understand what the other person is saying, it is fine.
Anonymous
Lol. You dont have to go and change messages in the past. As long as we understand what the other person is saying, it is fine.
i mean correcting that text changes the nature of the debate. now it is just > It may be 0x312D0000 0x312D as well depending on whether the system is big endian or little endian. >> no (not necessarily) > Where did i say that it was necessary? it is just that there can be an implementation like this. >> true
Anonymous
i mean correcting that text changes the nature of the debate. now it is just > It may be 0x312D0000 0x312D as well depending on whether the system is big endian or little endian. >> no (not necessarily) > Where did i say that it was necessary? it is just that there can be an implementation like this. >> true
So there is nothing to debate then as long as you agree that there may be a hypothetical implementation which takes endianness into account. How many implementations do that is a different question. Like you showed, GCC, Clang and MSVC just use shifting and MSVC has this added quirk of storing the characters in memory from left to right starting from low address to high address while it is stored the opposite way in GCC. MSVC implementation is more debug friendly. So 'abcd' would display as abcd in a debugger while it will be displayed as 'dbca' for GCC. Both would evaluate to the same int value however using the same shifting logic. But that is anyway digression.
Anonymous
Hello, i have been trying to complete a few program but i couldn't, i have to learn and teach those programs to my younger brother, is there anyone willing to help?
Anonymous
Hey guys this is to anyone that want to learn c language 🙂 so we can learn together oh if you can mentor us then we can learn from you that's good please please help your brother
Anonymous
Please you can talk to me I'm here
Anonymous
We can learn together bro
Thomas shelby
int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }
Thomas shelby
Can anyone tell me what does if(-1<=size ).....this condition mean ???
Thomas shelby
What's exactly -1 mean???
Thomas shelby
Is it correct to declare a main fn without its return type???
Thomas shelby
Can anyone help me with this ?????