6

After waiting for 6 months for my ability to post questions on Stack Overflow again I did a careful job at trying to be as specific and detailed as possible and I was met with a downvote again, without a reason for the downvote being given.

My question Change variables in place in void function without arguments was downvoted out of the blue.

Is this because someone disliked the idea of someone using global variables in their program?

My account again cannot ask questions.

How can I improve my question?

3
  • It's confusing. Reading para 1, most developers are already thinking 'OK, why not mallocate some pointers and realloc them if needed. That's an obvious solution, so what is the problem....' and so off they go looking for multithreading issues and the like, that do not seem discernable. It's possible that someone downvoted for bringing up a problem that doesn't exist:( Sep 15, 2019 at 17:11
  • Anyway, it's now got +2. Not sure why, I would have downvoted it. It's safe from me now - I don't up/down q/a I mention on meta:) Sep 15, 2019 at 17:17
  • @MartinJames I don't know. I was a frequent user of math.stackexchange, and I think I've only downvoted one or two times, and have had only one or two downvoted questions among hundreds. I don't know why stackoverflow is so different in this respect.
    – sequence
    Sep 16, 2019 at 14:05

1 Answer 1

12

I can see multiple reasons about why someone could have downvoted your question:

  1. You don't show any minimal, reproducible example. You just put there some dummy code instead of an actual working example showing what you tried and explaining why it didn't work.

  2. Your question seems really unclear. You are talking about global variables, and then say you can't find a way to initialize them from a function. They are global, why should you need to pass them as parameters? In fact, someone also pointed this out in the comments:

    But why do you need to pass arguments if they are global for the whole program? Can you just use it inside a function without args?

  3. You commented with a code snippet that showed how what you're asking for could be done, basically answering your own question:

    @DavidRanieri If I write code like this, will it actually change the arrays in place? void get_bcs() { GammaL = malloc(nequ*sizeof(double)); for (int i=0; i<nequ; i++) { GammaL[i] = BCgammal[i]/(0.5*BCalfal[i]-BCbetal[i]*rdx); } } It doesn't look like I'm changing by reference here.

    And someone else replied assuring you that said code is fine:

    @sequence The code in your own comment seems fine. I'm not sure what you mean by " It doesn't look like I'm changing by reference here" but the code will for sure update the value of both the pointer and the pointed to objects

  4. Even more comments showing that the question really is unclear, or in other words you seem to have failed to explain what you were trying to do:

    n.m.: You are asking how to avoid passing your variables to fill_array as arguments. I presume you are not passing these variables to all other functions that use them, otherwise it would not make any sense to make them global. You have many functions that use your variables without having them in the parameter list. Why is fill_array having them?

    You: @n.m. That's because I thought that it wouldn't be possible to fill the arrays in place without passing them to fill_array by reference, but 4386427 has straightened this out now.

  5. Given the above, this really looks like a XY problem at first glance. It is really, really hard to try to solve such problems without having the asker re-formulate them or clarify them. In the meantime, anybody who reads the question would find it hard to understand and that could be another reason for a downvote.

1
  • 1
    Thanks for clarifying, I'll try to edit it more. To be honest, I haven't seen a lot of questions with minimal working examples, so I thought mine didn't need it, and some code would be enough to explain what I meant. Concerning the void function without arguments and my comment with correct code - that was actually the result of n.m.'s clarification of that nuance of global variables as opposed to non-global ones. In essence that's the answer that I needed.
    – sequence
    Sep 15, 2019 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .