« first day (1838 days earlier)      last day (1021 days later) » 

mr5
1:15 AM
@nwp Tizen Studio is weird. I'm even getting compile errors for variable names that doesn't exist.
 
 
2 hours later…
mr5
2:49 AM
Do you guys know the technique using std::bind to skip optional parameters?
 
 
6 hours later…
nwp
8:59 AM
@mr5 I recommend you forget that std::bind exists and use lambdas instead.
If you insist on doing it the bad way look at placeholders.
 
@nwp I think with "optional parameters" he means arguments with a default value
not sure that's even possible with std::bind
does work with a lamdba though
 
nwp
@CătălinaSîrbu The 7 probably shouldn't be hardcoded; instead you should base the overflow logic on using the highest value in your enum directly. I'm not sure wrapping around is what you want. Also usually people use operator++ instead of a named function because Game game; game++; looks nicer than Game game; skipToNextPuzzle(game);.
 
9:17 AM
I have trouble understanding why streams must be passed by reference (&). Most answers say "it wouldn't make sense to have two copies that point to the same thing" but why not? Why couldn't it be understood that two different instances do point to the same stream. Or just omit the &?
 
nwp
Say you have std::cout. You make a copy. You print "Hello" to one std::cout and "World" to the other. What is the user supposed to see on the screen?
If your answer is "HelloWorld" then just take a pointer to std::cout and pretend that's the stream. Then you can copy it all you want and it behaves the way you want it to.
 
@northerner you could model it that way, in that model you would just understand the "stream" to be a handle only. But in C++ they chose differently
 
nwp
Normally copying means to actually copy the object, but there are for example file streams and file systems typically do not allow to have 2 files with the same name and location, so you just cannot copy them.
 
making the stream object not just represent a stateless handle also makes it easier to introduce additional abstractions and state like they do in C++ with the std::ios::hex and other formatting tags
Now, I happen to think that most of the stateful formatting flags are not ideal, but it's decision they made at the time
 
 
5 hours later…
2:03 PM
Howdy folks. I have little experience with Makefiles and I'm trying to set a default value for an optional argument inside a recipe, like this:
dist:
	if [ ! ${VERSION} ]; then VERSION='foo'; else echo "VERSION SET"; fi

	echo $(VERSION)
	exit 1
I know I could place VERSION ?= "foo" outside the recipe, but I would like to apply this default logic only to this specific recipe, since other recipes also use VERSION parameter
is what I'm trying to do possible in Makefile? Is it against Makefile philosophy in any way and should I give up?
 
Can someone explain to me the difference between indirection operator and a pointer? I understand that a pointer 'points' to a data type at a specific address in memory, but what is the purpose of a indirection operator?
 
nwp
One purpose is to make a class like std::unique_ptr behave like a pointer.
 
@nwp ok so I am right in thinking that the indirection operator returns the value at the specific address and a pointer is just the address itself?
 
nwp
It's one option, but you can do other things as well. In theory you can return a newly allocated pointer every time and not even have any specific address.
Specifically std::shared_ptr can point to one object that has its memory managed but can return a different object when you dereference it.
 
4 messages moved from Lounge<C++>
 
3:02 PM
Hi, I've asked this question some time ago but here it is again. If you declare a variable inside of a case, function, loop, does this makes it consume more memory? isn't that variable erased after each iteration and redeclared when reetering the function / loop
 
Generally speaking no, but it can have an impact on initialization
if you declare a complex type and don't immediately initialize it then it has to get default initialized every single time. It also needs to get destroyed at the end of the loop body
But if you're reinitializing the value every single time you're paying those costs anyway so pick your poison. Personally I prefer the limited scope.
 
it's pretty much only "erased" if it's not trivially destructable. I think even with default compilation setting, without any extra optimizations it doesn't keep increasing/decreasing the stack pointer for every single variable/loop
 
But can it potentially have impacts: yes, particularly if you're allocating memory every single time you use it. For example I might not put a vector I'm using a buffer inside the loop
because I can just grow it in the loop and then deallocate the memory all at once
IIRC the standard would allow the program to elide the allocations if it can figure out what I'm doing (reserving a set amount for example). But AFAIK no compiler actually does that
 
can i run out of ram doin this?
while(1)
{
int x = do some calcs();
}
 
no, not unless do_some_calcs() leaks memory
 
3:15 PM
^
or is recursive
 
that snippet itself doesn't even dynamically allocate any memory
 
is there any diff between that exaple and declaring int x outside loop?
 
Yes x has its scope limited to the loop
so it won't be visible outside the loop, this is generally seen as a good thing
 
the generated code would be the same with even mild optimizations
 
something with bigger impact would be something with a vector
 
3:17 PM
how can i get out of memory only using static allocated builtin datatypes?
 
while(1){
   std::vector<int> bar(1000);
}
I mean if you did a c style array that was stupid big you could
 
like Mgetz said, infinite recursion
 
char foo[INT_MAX]
but recursion is the more likely answer
example of how to make the runtime hate you godbolt.org/z/ssEf8hYvM
 
just curious, why do you ask?
 
3:24 PM
i have a problem using atmega uC and it seems to me like it runs out of sram
because if I comment some lines of code it starts working again
the problem is that what seems to cause the problem is a switch case
 
does the switch have brackets? or what is it doing?
e.g. do any of the cases have brackets in them
case foo:
{
}
break;
 
yes, all of them
and also the break is inside the {}
one of my team member posted today a question on the arduino forum. Here is a link
and you can see the case I did
 
I mean there are some things you can collapse to make the code cleaner but the error isn't about running out of memory per se. But about having a code segment that's too big
 
like running out of flash? "Sketch uses 14414 bytes (5%) of program storage space"
you mean i have too much text ?
 
maybe I'm reading that wrong...
where and how is array_pini_220v defined?
 
3:38 PM
for example right now I modified the case with if statements and it looks like it's working...
    const byte array_pini_220v[8] = {

        PIN_BEC1,
        PIN_BEC2,
        PIN_BEC3,
        PIN_BEC4,
        PIN_BEC5,
        PIN_BEC6,
        PIN_BEC7

    };
 
yeah, I was about to ask about that too. Because I'm not confident in that digitalWrite(array_pini_220v[birdbox_number], LOW);
maybe try printing the value of birdbox_number or at least bounds_checking
 
Style thing: never explicitly set the length of a constant array
Because you have an uninitialized byte likely at the end there
if std::array is available I'd use that and a ranged for honestly btw
it does look like in one of your methods you're modifying globals?
pressed_button = getPressedButton();
ret = false;
 
yes it's what I asked you
if t here is a problem int ret = false
int pressed_button =
instead of using globals
 
no that's safer than using globals
globals always use memory
and have thread safety issues if this is called from an interrupt
btw don't call that from an interrupt
 
3:45 PM
no interrupts are used
I told you, just replacing the switch case with an if statemend seems to solve the problem
maybe a bug in software?
@Mgetz also
, case foo:
{
}
break;
case foo:
{

break;
}
 
no difference between the two
 
is any difference?
thanks
 
Personally I always place the break outside
but that's a style thing because I don't like indicating that the break is from the inner scope
 
and another question defines over constants...?
as you said constants would be global and would take permanent amount of space
defines what space do they use?
 
depends on what it is?
and how you define them
 
3:48 PM
integers
 
on any optimization level they would be inline insofar as they are declared const
 
basically alias for some numbers
 
or constexpr
actually even on no optimization the compiler will usually inline godbolt.org/z/MoKaYW4Mz
defines on the other hand have no type information, and can do weird things when you actually use them
 
so constexpr is more suitable here
 
it's my go to yes
 
3:52 PM
or it doesn't matter for this example
 
but it may not completely matter
regardless avoid defines in most cases
 
ok thanks for advice
 
FWIW if you want to dramatically decrease your generated code size you can make functions that only need to exist in one file exist in an unnamed namespace or as static
without external linkage the compiler can optimize the heck out of them
 

« first day (1838 days earlier)      last day (1021 days later) »