Artöm
Artöm
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
Artöm
Theres a difference in getting help and making someone do your work
Artöm
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
Shubh
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?
MᏫᎻᎯᎷᎷᎬᎠ
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
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
Hermann
are there best practice?
Anonymous
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.
MᏫᎻᎯᎷᎷᎬᎠ
Mp
who knows algorithm and data structure`/?
Anonymous
MᏫᎻᎯᎷᎷᎬᎠ
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
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
You can't define an entity two times I guess
MᏫᎻᎯᎷᎷᎬᎠ
And @ollirz said something about internal link
What is that?
MᏫᎻᎯᎷᎷᎬᎠ
olli
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ᏫᎻᎯᎷᎷᎬᎠ
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
MᏫᎻᎯᎷᎷᎬᎠ
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.
MᏫᎻᎯᎷᎷᎬᎠ
Joo
How can an array of pointer to a data type be declared
Joo
What is it used for?
Anonymous
Joo
Anonymous
How?
Like any other array
Joo
So i want they are declared and initialized
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?
olli
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