/home/aleksandr/
yes why not
/home/aleksandr/
I know python, and I'm just curious to understand how much faster C ++ is faster . I want to write a simple bot for fun
klimi
Anmol
/home/aleksandr/
Anonymous
klimi
no
Then you will have to do that or tell your compiler where your lib is
/home/aleksandr/
Anmol
klimi
Uhm..... What's your operating system and what compiler you are using? Also I would like to have the link to that lib you found online
/home/aleksandr/
Dima
you can use other languages, sometimes its called interop
valerie
hi, i really need help with my assignment, i have written a code but i doesnt seem to work
valerie
is anyone available to help
vinícius*
ʟᴏɴᴇᴡᴏʟꜰ
I am a beginner in C I was reading let us C but some of my seniors advised me to buy Depth in c or E.Balaguruswamy...
ʟᴏɴᴇᴡᴏʟꜰ
Which one should I buy...?🤷♂️😊
ʟᴏɴᴇᴡᴏʟꜰ
okay thanks...😊
Anonymous
I recommend C Primer Plus
Anunay
K&R is good afaik
Yeiner Morales
/programming
Manish
Hi , I have to extract file location from sockaddr_un addr to change permission of socket file. Help appreciated
Md
hi
Anonymous
edit: nvm i'm dumb
Vitaliy ◀️TriΔng3l▶️
char is just the smallest addressable numeric type, yes
SR
Assuming, integer is 2 byte, What will be the output of the program? #include<stdio.h> int main() { printf("%x ", -2<<2); return 0; }
SR
Tell me
Vitaliy ◀️TriΔng3l▶️
Though signedness of just char depends on the compiler/platform, so explicit signed char or unsigned char should be preferred for numbers
Vitaliy ◀️TriΔng3l▶️
Pavel
By the way, is C++20 forces it's to be two's compliment or it didn't make to the standard?
Vitaliy ◀️TriΔng3l▶️
300, 44 (on architectures with 8-bit unsigned char and at least 10-bit int)
Vitaliy ◀️TriΔng3l▶️
two's complement is how signed integers are stored
Vitaliy ◀️TriΔng3l▶️
-1 int8_t being 0xFF, -2 being 0xFE
Vitaliy ◀️TriΔng3l▶️
according to char being 8-bit
Vitaliy ◀️TriΔng3l▶️
by two's complement I mean that shifting a negative number left would multiply it by 2, right would divide it by 2 (with sign extension)
Vitaliy ◀️TriΔng3l▶️
and that 0xFF + 1 = 0
Vitaliy ◀️TriΔng3l▶️
Unsigned numbers are just numbers, nothing special about their encoding, so they have clearly defined wrapping in the standard, for instance
Vitaliy ◀️TriΔng3l▶️
2's complement is the way signed numbers are stored
Vitaliy ◀️TriΔng3l▶️
like 0, 1, 2, …, 255
Vitaliy ◀️TriΔng3l▶️
casts just drop the upper bits
Vitaliy ◀️TriΔng3l▶️
casting uint32_t to uint8_t just drops the upper 24 bits
Vitaliy ◀️TriΔng3l▶️
In uint8_t — yes, in unsigned char — yes if it's 8-bit on your target architecture
Vitaliy ◀️TriΔng3l▶️
Because arithmetic promotes them to int
Vitaliy ◀️TriΔng3l▶️
or to unsigned int, I'm not 100% sure
Vitaliy ◀️TriΔng3l▶️
Cast the result to uint8_t, like in your second example
Anonymous
Anonymous
I am a beginner can someone help me with the problem
Vitaliy ◀️TriΔng3l▶️
It doesn't really matter, but why would you want to do math in uint8_t specifically?
Vitaliy ◀️TriΔng3l▶️
For simplicity of writing arithmetic statements, and also CPUs now work mainly with 32-bit or 64-bit registers
Vitaliy ◀️TriΔng3l▶️
and on some, especially RISC architectures, it's not uncommon to only have explicit loading (zero-extending for unsigned, sign-extended for signed) and storing for 8-bit numbers, with arithmetic only done for 32- or 64-bit numbers
Vitaliy ◀️TriΔng3l▶️
%d is signed decimal of int type, %hhd is specifically for signed char, %hhu is for unsigned char
Vitaliy ◀️TriΔng3l▶️
but no, formatting has nothing to do with promotion to int
Vitaliy ◀️TriΔng3l▶️
If you format 300 as %hhu you'll get 44 in the resulting string
Vitaliy ◀️TriΔng3l▶️
no, %d has no effect on what is happening on the language side
Vitaliy ◀️TriΔng3l▶️
printf is just a function, that takes the format string simply as a pointer
Vitaliy ◀️TriΔng3l▶️
formatting has no effect on anything happening in the language, as I said
Vitaliy ◀️TriΔng3l▶️
printf(formatStringFromElsewhereMaybeEvenLoadedFromFileOrNetwork, a + b) would also work
Vitaliy ◀️TriΔng3l▶️
https://stackoverflow.com/questions/46073295/implicit-type-promotion-rules
Whenever a small integer type is used in an expression, it is implicitly converted to int which is always signed. This is known as the integer promotions or the integer promotion rule.
Formally, the rule says (C11 6.3.1.1):
If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.
Vitaliy ◀️TriΔng3l▶️
a + b is (int)a + (int)b in this case
Serenity
Hello, I've a pretty basic question . Let's say I have declared an array of chars a[100] , and then assigned '\0' to the first element in the array (a[0] = '\0') . My question is whether from now on the array will be counted as a string and I won't have to add the null character manually after each operation , thanks for the help.
Alex
Serenity
If I define char a[100] so it would be just a regular array of chars right ?
Alex
yes
Serenity
As I set in '\0' somewhere in the array , would it be automatically converted into a string
Serenity
?
Alex
I don`t know what is definition of "string" in C. I am not it is presented at all
Asdew
A string, char*, is just an array of characters, char, which ends with \0, null.
Alex
no conversion is made of course, you just set \0 to some specific byte
Stefan
Stefan
you should not assume it in the first place
Stefan
Stefan
array of characters? null terminated block of memory of characters?
Stefan
or like c++, std::string which is like pascal, a counter + block of memory of characters
Serenity
I'll try to explain better. Let's say I assigned '\0' to the first element in the array (which consists of 100 elements) - and I execute strcpy on the array , then will '\0' be automatically added to the end of the array ?
Stefan
undefined
Alex