side-effects

VLAs and side-effect in sizeof's operand

霸气de小男生 提交于 2019-12-20 17:29:23
问题 I know that sizeof never evaluates its operand, except in the specific case where said operand is a VLA. Or, I thought I knew. void g(int n) { printf("g(%d)\n", n); } int main(void) { int i = 12; char arr[i]; // VLA (void)sizeof *(g(1), &arr); // Prints "g(1)" (void)sizeof (g(2), arr); // Prints nothing return 0; } What is going on? Just in case, this is compiled with GCC 5.1 on Coliru. 回答1: It seems that I should think twice before posting, because it struck me right after I did. My

Side effects of changing filter and requirements of an existing app in Android Play/Market

妖精的绣舞 提交于 2019-12-20 10:38:37
问题 No previous questions about it, so here I ask. Background: I have an old app, in free and paid versions, in the Play Market. I created a new version, radically changed and with a different payment system (free app + in app purchases only, no more a paid version: reduce maintenance costs). minSdkVersion also changed from 1.5 to 2.1. Because of all those differences, I decided to upload a new app, not just update the current one (i.e., not selectively provide a new apk for API 7+ --- multiple

Java volatile and side-effects

烂漫一生 提交于 2019-12-20 09:46:09
问题 Oracle's documentation on atomic access (at http://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html) says this: "a volatile variable establishes a happens-before relationship... . This means that ... when a thread reads a volatile variable, it sees not just the latest change to the volatile, but also the side effects of the code that led up the change." I'm having trouble wrapping my head around that. I understand how volatile variables work (in >= Java 5), but I'm wondering

C# Paradigms: Side effects on Lists

点点圈 提交于 2019-12-18 11:53:50
问题 I am trying to evolve my understanding of side effects and how they should be controlled and applied. In the following List of flights, I want to set a property of each flight satisfying a conditions: IEnumerable<FlightResults> fResults = getResultsFromProvider(); //Set all non-stop flights description fResults.Where(flight => flight.NonStop) .Select(flight => flight.Description = "Fly Direct!"); In this expression, I have a side effect on my list. From my limited knowledge I know for ex.

Undefined behavior in c/c++: i++ + ++i vs ++i + i++ [duplicate]

旧城冷巷雨未停 提交于 2019-12-18 09:45:25
问题 This question already has answers here : Why are these constructs using pre and post-increment undefined behavior? (14 answers) Closed 2 years ago . Imagine that we have the code below: int i = 1; int j = i++ + ++i; I know that this is a Undefined Behavior, because before the semicolon, which is a sequence point, the value of i has been changed more than once. It means that the compiler may have two possibilities even if the precedence of operator plus is Left-to-Right: case 1) take the value

CListCtrl with checkboxes questions

这一生的挚爱 提交于 2019-12-18 09:44:06
问题 The List Control is defined as Single Selection on the resources. Question 1 I want to have a checkbox on the header of first column of my CListCtrl . On the OnInitDialog I have m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); CString s; s.LoadString(IDS_COLUMN1); #ifndef HDS_CHECKBOXES // Copied from Microsoft SDKs\Windows\v7.0A\Include\CommCtrl.h #define HDS_CHECKBOXES 0x0400 #endif CHeaderCtrl& header = *m_list.GetHeaderCtrl(); header

Why is the raising of an exception a side effect?

戏子无情 提交于 2019-12-17 22:33:39
问题 According to the wikipedia entry for side effect, raising an exception constitutes a side effect. Consider this simple python function: def foo(arg): if not arg: raise ValueError('arg cannot be None') else: return 10 Invoking it with foo(None) will always be met with an exception. Same input, same output. It is referentially transparent. Why is this not a pure function? 回答1: Purity is only violated if you observe the exception, and make a decision based on it that changes the control flow.

When exactly does a method have side effects?

岁酱吖の 提交于 2019-12-13 12:04:38
问题 As I always understood it, any change to the programs state (or anything to do with IO) is a side effect. It does not matter, whether the change occurs in a global variable or in a private field of the object the method is called on. It follows that all methods which do not return anything either do nothing at all or have a side effect. My confusion comes from one of our university's instructors (who is still a student and thus not omniscient yet;) ) telling me setters don't have side effects

Getter with side effect

蹲街弑〆低调 提交于 2019-12-12 07:25:32
问题 I create a class whose objects are initialized with a bunch of XML code. The class has the ability to extract various parameters out of that XML and to cache them inside the object state variables. The potential amount of these parameters is large and most probably, the user will not need most of them. That is why I have decided to perform a "lazy" initialization. In the following test case such a parameter is title . When the user tries to access it for the first time, the getter function

Is it bad practice to purposely rely on Linq Side Effects?

依然范特西╮ 提交于 2019-12-11 10:34:51
问题 A programming pattern like this comes up every so often: int staleCount = 0; fileUpdatesGridView.DataSource = MultiMerger.TargetIds .Select(id => { FileDatabaseMerger merger = MultiMerger.GetMerger(id); if (merger.TargetIsStale) staleCount++; return new { Id = id, IsStale = merger.TargetIsStale, // ... }; }) .ToList(); fileUpdatesGridView.DataBind(); fileUpdatesMergeButton.Enabled = staleCount > 0; I'm not sure there is a more succinct way to code this? Even if so, is it bad practice to do