constexpr size_t ARRAY_LENGTH = 50;
T arr[ARRAY_LENGTH];
C would be just outdated if it wasn't for embedded systems, operating systems and drivers.

Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Shield
Bulgaria4824 Posts
February 12 2017 00:58 GMT
#16821
constexpr size_t ARRAY_LENGTH = 50; T arr[ARRAY_LENGTH]; C would be just outdated if it wasn't for embedded systems, operating systems and drivers. ![]() | ||
Deleted User 3420
24492 Posts
February 12 2017 01:18 GMT
#16822
like
| ||
Shield
Bulgaria4824 Posts
February 12 2017 01:45 GMT
#16823
![]() | ||
Deleted User 3420
24492 Posts
February 12 2017 01:47 GMT
#16824
![]() *goes and checks* | ||
Shield
Bulgaria4824 Posts
February 12 2017 01:51 GMT
#16825
const int SIZE = 5; int array[SIZE]; Fine in C++. Not compiling in C. Fuck you C. :D That said, if I was going to do it properly in C++, it would be: constexpr size_t SIZE = 5; Your example compiles and runs fine in C and C++. However, I'd advise you to stick with size_t instead of int for size of array. size_t is an unsigned integer or unsigned long long, so it doesn't make sense for size of arrays to have a negative value. ![]() | ||
Hanh
146 Posts
February 12 2017 03:17 GMT
#16826
If you want to allocate dynamically from the stack, there is the function 'alloca' | ||
Shield
Bulgaria4824 Posts
February 13 2017 00:05 GMT
#16827
On February 12 2017 12:17 Hanh wrote: These dynamic arrays are allocated from the stack. Unless you can make sure that they are small you shouldn't spend stack space because it's only typically a few K in size. If you want to allocate dynamically from the stack, there is the function 'alloca' Good to know if I ever have to write pure C code without malloc. I remember at university there was some task to ask user for numbers. Catch was not knowing how many they are, so we had to do some dumb stuff like #define ARRAY_LENGTH 1000 And hope it's enough... Good thing is you have std::vector<type> in such cases, but alas, it was a C module. I suppose you can still do a dynamic array like vector, but you will just have to reinvent the wheel. | ||
Nesserev
Belgium2760 Posts
February 13 2017 00:40 GMT
#16828
| ||
Blisse
Canada3710 Posts
February 13 2017 02:43 GMT
#16829
| ||
dsyxelic
United States1417 Posts
February 13 2017 03:09 GMT
#16830
'solved' I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT Anyone know why this is? I'm pretty sure I did this correctly but I guess not edit: holy lol apparently def whatever (x, self) doesn't work? I did not know self had to be the first argument. sigh I hate syntax issues lol | ||
Blisse
Canada3710 Posts
February 13 2017 03:34 GMT
#16831
On February 13 2017 12:09 dsyxelic wrote: snippet of my code in python:
I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT Anyone know why this is? I'm pretty sure I did this correctly but I guess not AFAIK def INSERT(x, p, self): should be def INSERT(self, x, p): otherwise you should be calling x.last | ||
dsyxelic
United States1417 Posts
February 13 2017 03:36 GMT
#16832
On February 13 2017 12:34 Blisse wrote: Show nested quote + On February 13 2017 12:09 dsyxelic wrote: snippet of my code in python:
I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT Anyone know why this is? I'm pretty sure I did this correctly but I guess not AFAIK
should be
otherwise you should be calling x.last thank you haha I just realized that. IDE's are helpful. I tried my code in an IDE and it basically told me what to fix right away. I should use the IDE more when I have syntax problems. | ||
Nesserev
Belgium2760 Posts
February 13 2017 03:46 GMT
#16833
| ||
dsyxelic
United States1417 Posts
February 13 2017 04:03 GMT
#16834
On February 13 2017 12:46 Nesserev wrote: Show nested quote + On February 13 2017 12:09 dsyxelic wrote: snippet of my code in python: 'solved' I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT Anyone know why this is? I'm pretty sure I did this correctly but I guess not edit: holy lol apparently def whatever (x, self) doesn't work? I did not know self had to be the first argument. sigh I hate syntax issues lol Self has to be the first parameter of your class method, because the object on which the method is called, is always passed as the first argument. (The parameter's name doesn't have to be self though... but you should call it self anyway, because conventions.). Second, I also noticed that you made maxlength, elements and last class member, so basically every instance of ListArray would share those variables... if you have more than one instance of said class, they'd probably overwrite each other constantly. Instead, instance members should be initialized in the __init__ function, any other class function, or just x.member from the "outside".
Basically, instance members have to be tagged on. When you say x = ListArray(), you start out with an "empty" object, and __init__ for ListArray is run, which first adds the elements member, and then the last member. Thank you, that was really helpful. That was silly of me. Everything's working great now, thank you! | ||
Manit0u
Poland17187 Posts
February 13 2017 11:11 GMT
#16835
Fuuuuck me! Why do I have to be so poor? ![]() | ||
Nesserev
Belgium2760 Posts
February 13 2017 17:02 GMT
#16836
| ||
Shield
Bulgaria4824 Posts
February 13 2017 19:07 GMT
#16837
| ||
Manit0u
Poland17187 Posts
February 13 2017 21:25 GMT
#16838
On February 14 2017 04:07 Shield wrote: I've been asked if there is any significant technology coming up for computing, but I don't know anything major other than quantum computer. Is there anything else? Besides quantum computing you have some closer goals, like everything working under 64bit architecture, parallelism everywhere and all programs being able to utilize all of the cores. But that's more on the software side. In hardware we already have some new materials like graphene, some cooling technologies without the use of fans or water (plates that bend under temperature and generate air flow) etc. etc. Currently we're pretty much at the limit of silicon and other materials so until something new comes along and is cheap enough to mass-produce we're pretty much done (notice that for some years now CPU clock speed doesn't really increase, just the number of cores does). | ||
Deleted User 3420
24492 Posts
February 13 2017 22:26 GMT
#16839
give an infinite subset X in Q that contains no elements in set N my answer: Q less than 0 (this one seemed easy but it's weird so im checking) give an infinite subset X in R that contains no elements in set Q my answer: the set of irrational numbers? though I know of no actual proof that this set is infinite in size, I am just guessing it is find an infinite domain where the statement is true OR show that there is NO such domain. explain. then do the same but attempting to show that the statement is false. (for all x)(there exists y)[(x < y < 1 ) and (not (x < z < y) ] for False, I say the natural numbers. If y < 1, then y must be 0. So x cannot be less than y. for True, we know we our domain must not be a dense set (I've got this right, correct?) since there is no z between x and y. So we are dealing with integers or some such. But there doesn't seem to be any domain that actually works here, because we can't find a y > x and less than 1 in a set that isn't dense. | ||
spinesheath
Germany8679 Posts
February 13 2017 23:03 GMT
#16840
On February 14 2017 07:26 travis wrote: give an infinite subset X in Q that contains no elements in set N my answer: Q less than 0 (this one seemed easy but it's weird so im checking) That works. Also any subset that is each element in N plus some fraction between 0 and 1, or 1 divided by all integer numbers greater than 1 and so on... On February 14 2017 07:26 travis wrote: give an infinite subset X in R that contains no elements in set Q my answer: the set of irrational numbers? though I know of no actual proof that this set is infinite in size, I am just guessing it is Can get real creative with this one too. Like I'm pretty sure that the set of all n-th roots of 3 where n in N and n > 1 should fit. Integer (except 0) multiples of pi (or any irrational number) work just as well. | ||
| ||
![]() StarCraft 2 StarCraft: Brood War Hyuk Dota 2![]() BeSt ![]() Shuttle ![]() Mini ![]() Harstem ![]() hero ![]() Snow ![]() TY ![]() Zeus ![]() Sharp ![]() [ Show more ] Counter-Strike Heroes of the Storm Other Games tarik_tv44361 B2W.Neo1441 DeMusliM674 sgares525 crisheroes492 Fuzer ![]() hiko298 Hui .258 Liquid`VortiX160 ArmadaUGS155 QueenE124 RotterdaM92 KnowMe34 JuggernautJason7 Organizations
StarCraft 2 • StrangeGG StarCraft: Brood War![]() • intothetv ![]() • AfreecaTV YouTube • Kozan • IndyKCrew ![]() • LaughNgamezSOOP • Laughngamez YouTube • Migwel ![]() • sooper7s Dota 2 League of Legends |
Replay Cast
OSC
PiG Sty Festival
Clem vs Bunny
Solar vs Zoun
Replay Cast
BSL Nation Wars 2
Korean StarCraft League
PiG Sty Festival
herO vs Rogue
ByuN vs SKillous
SC Evo Complete
[BSL 2025] Weekly
Replay Cast
[ Show More ] SOOP Global
ByuN vs Zoun
Rogue vs Bunny
PiG Sty Festival
MaxPax vs Classic
Dark vs Maru
Sparkling Tuna Cup
BSL Nation Wars 2
The PondCast
|
|