Artöm
"the number of elements different from the last element"I am not writing correctly
Write a for loop, for each element check if it is equal to last element
Artöm
G B you wont learn C without reading about the most basic stuff
Anonymous
no, it’s not so easy. I have little time. I participate in the program and must end the result. this is a new world for me and I try
Anonymous
I just need help getting started
olli
well so far you mostly asked someone to do your assignments
Anonymous
and if for a certain period I do not show the result, I will not go to the second round
Artöm
I wish I knew a book with short explanations to suggest to people like you
Anonymous
I just need help getting started
OK #include <stdio.h> int main() { printf("yes"); } You are now basically overqualified to work at any tech startup
Artöm
Theres a difference in getting help and making someone do your work
Anonymous
know it's even hard for me to ask questions I use google translate and no, I know English so well and/ and I do not even make the case for me.but I am very grateful to all those who help.and the cat reproaches all those so / but I am trying and will be tortured with or without you
Anonymous
http://www.cplusplus.com/doc/tutorial/functions2/ I use this site,but I learn faster on tasks. i the meaning of this tournament they teach us from c++
Anonymous
but what they will explain in lectures is not in the tasks....and for this it is difficult for me even more, I understand for many may the questions may seem ridiculous
Hermann
Is it bad practice to declare a static variable in the header file?
olli
Is it bad practice to declare a static variable in the header file?
I don't like that idea as most people might not be aware of the implications.
MᏫᎻᎯᎷᎷᎬᎠ
What are the implications of it?
Hermann
i think share data
Alex
What's wrong with it?
you will have copy of this variable in every compilation unit with this header. what task are you trying to solve using this variable?
MᏫᎻᎯᎷᎷᎬᎠ
i think share data
Yeah data are shared all time + I think inline solved that definition and declare problems
olli
The data gets duplicated for every CU. Potentially wasting memory. e.g. foo.hpp #pragma once #ifndef FOO_HPP_ #define FOO_HPP_ #include <cstdint> static uint64_t foo = 1337; void bar(); #endif foo.cpp #include <cstdio> #include "foo.hpp" void bar() { foo = 1338; std::printf("%llu\n", foo); } app.cpp #include <cstdio> #include "foo.hpp" int main (int argc, char **argv) { bar(); std::printf("%llu\n", foo); return 0; } the unsigned integer in foo.cpp and app.cpp are not the same. So this will print 1338 1337
olli
You mean bar function?
I should sleep -.- yeah, bar function or foo.cpp in general
Hermann
are there best practice?
Anonymous
are there best practice?
Yes Use something else
MᏫᎻᎯᎷᎷᎬᎠ
I should sleep -.- yeah, bar function or foo.cpp in general
I don't see the point Bar () just adjusted the value because you called it That's all
olli
I don't see the point Bar () just adjusted the value because you called it That's all
yes, but defining the variable in the header might give the impression that you can access the same variable from different source files - but you can't because it gets duplicated. Changing foo defined in the header in the bar function has no impact on the value of foo in the other source file
olli
If you want to have two distinct foo (one in each source file) I would suggest defining them there and not in a shared header.
Mp
who knows algorithm and data structure`/?
MᏫᎻᎯᎷᎷᎬᎠ
It's related to execution process What's get called first changes it first
No class or a function will decide to change it by itself without a caller All of them will refer to the main function at the end
MᏫᎻᎯᎷᎷᎬᎠ
+ Why there is a duplication I thought header guards prevent that
olli
the thing is tho, if you can't "share" the variable why even define it in a header? I would argue that is an implementation detail and should not be exposed. You include the header and not you have this variable defined, what if it is a huge lookup table? Do you really want to duplicate the table over and over again? the static defines the variable to be internally linked which basically prevents it from being exposed to the linker and hence it will never be accessible from any different CU
Alex
+ Why there is a duplication I thought header guards prevent that
it prevents. so in one compilation unit you have one variable. but if you have two source files, in each the same header file is included, you have two copy of the same variable
MᏫᎻᎯᎷᎷᎬᎠ
You can't define an entity two times I guess
MᏫᎻᎯᎷᎷᎬᎠ
And @ollirz said something about internal link What is that?
Alex
Won't that cause any error?!🤔
if you omit header guard you will obtain error
olli
So that's what differs it from global variable What's the lookup table
E.g. sometimes you want to approximate a sine wave on embedded systems. Since some have to emulate float operations in software they are pretty slow. Instead you define a lookup table to easily get an approximation.
Alex
And @ollirz said something about internal link What is that?
https://stackoverflow.com/questions/1358400/what-is-external-linkage-and-internal-linkage
MᏫᎻᎯᎷᎷᎬᎠ
https://stackoverflow.com/questions/1358400/what-is-external-linkage-and-internal-linkage
So static variables do not have any external linkage, right?
MᏫᎻᎯᎷᎷᎬᎠ
correct - they are internal
Even if it's from another file?!
MᏫᎻᎯᎷᎷᎬᎠ
Or a translation unit as what it's called
olli
It can be shared across multiple files (e.g the source file and header you include) but not multiple compilation units
MᏫᎻᎯᎷᎷᎬᎠ
How does the compiler accommodate that
MᏫᎻᎯᎷᎷᎬᎠ
Okay guys Thank you two Really appreciate it I hope I didn't nag on your heads xD
olli
How does the compiler accommodate that
with internal linkage the header basically defines the variable. For every compilation unit the header is included in, memory for this variable will be allocated and since it's internal the location will not be looked up by the linker (it's already known)
olli
if it's external the header basically must declares it's existence, the compiler assumes this variable exist but the location will later be filled in by the linker
olli
maybe this helps a bit [src: cs.odu.edu]
MᏫᎻᎯᎷᎷᎬᎠ
Thanks olli You should go to sleep now xD
olli
Thanks olli You should go to sleep now xD
gcc can show you the output after the preprocessor step by passing -E , e.g. https://godbolt.org/z/an5xKM Seeing how fast this can grow it makes sense to prefer forward declarations over includes.
Joo
How can an array of pointer to a data type be declared
Joo
What is it used for?
Anonymous
What is it used for?
To store pointers
Anonymous
How?
Like any other array
Joo
So i want they are declared and initialized
Anonymous
So i want they are declared and initialized
Like any other arrays Just combine your knowledge about arrays and pointers If you do not have the knowledge, gain some
Pavel
1) we won't solve your tests for you 2) is it only me or the question seems pointless (1st variant lmao)?
Tokin
Was it multiple choice answer?
neha raghuwanshi
I read all rules
neha raghuwanshi
And i agree with them
Tokin
Are you a compiler developer?
Tokin
Btw do ppl usually read the C standard? Those who aren't building a compiler?
Tokin
As a reference?
Tokin
Does it help alot?.. So do you also check out documentation of the platform.. You're building stuff for?
Tokin
Like x86 docs
neha raghuwanshi
I am student