Need help with expected primary-expression before 'int'

I got this expected primary-expression before 'int' error and I cannot figure out why.
Here is the code:
int c[18] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, - Pastebin.com (Couldn't post the whole thing here 'cause it's too many characters)
I'm getting the error on the int x; line in this function:

zn[0] =
  {
    int x;
    int y;
    if (pos == 0) {
      x = 15;
      y = 25;
    }
    if (pos == 1) {
      x = 12;
      y = 20;
    }
    if (pos == 2) {
      x = 9;
      y = 15;
    }
    if (pos == 3) {
      x = 6;
      y = 10;
    }
    if (pos == 4) {
      x = 3;
      y = 5;
    }
    if (pos == 5) {
      x = 0;
      y = 0;
    }

What, exactly, is zn, and why do you think you can assign it that value?

The compiler IS right. Whatever zn is, it can NOT be assigned that value.

bttshrbs:
I'm getting the error on the int x; line in this function:

This is not a "function". This particular piece of code is a nonsensical sequence of tokens. Until you describe what you are trying to do here, there's no way to say what is going on.

My crystal ball is telling me that whoever wrote that code was trying to use lambda-expressions. This is what it was supposed to look like

  zn[0] = [](int pos)
  {
    /* whatever */
  };

Note the ; after the last }. It is necessary.

And the same has to be done for all remaining z[] elements.

But I can't be sure of what else was "lost" from this code.

zn[0] is the first of 10 functions in an array. I read here Array of functions? - Programming Questions - Arduino Forum that it should work. If I misunderstood how to make an array of functions, please explain how should I do it.

bttshrbs:
zn[0] is the first of 10 functions in an array. I read here Array of functions? - Programming Questions - Arduino Forum that it should work. If I misunderstood how to make an array of functions, please explain how should I do it.

Nothing at the link you posted shows anything even close to what can make your code "work".

Once again, in my reply above you can see how to "fix" this code. But this not your code obviously. Whoever wrote this code it originally had those [](int pos) pieces in place. You didn't even manage to copy it properly.

In other words the code is obviously broken and some parts are missing. There's no way to be sure that my fix is sufficient to make it work.

Your solution seems to have fixed the problem, but now I’m getting the error that the function ‘twentyFourHourFormat’ was not declared in this scope

bttshrbs:
Your solution seems to have fixed the problem, but now I'm getting the error that the function 'twentyFourHourFormat' was not declared in this scope

Really? Sorry, I find it hard to believe.

In reality you are getting an error that says that twentyHourFormat was not declared in this scope. This is what you are trying to call from loop(). And the compiler is right. There's no such function in your code.

Please, make an effort to check basic spelling in your code by yourself, without asking the whole world to do it for you.

I kind of doubt you understand what this is:

void (*zn[num])(int pos);

Hint: It is not an array of functions. If you want to be able to parse complex data definitions, look at the Right-Left Rule, described here.

econjack:
I kind of doubt you understand what this is:

void (*zn[num])(int pos);

Hint: It is not an array of functions.

You are right.

However, just to make an example: in informal conversation we often refer to char * pointers as "C-strings". Formally, this is incorrect: char * can be a pointer to a C-string, but it cannot be a C-string itself.

The same distinction is often ignored (and forgiven) when talking about pointers to functions.

I've been using C for over 40 years and I have never seen an array of pointers to functions written this way. As to mangling terms, learning C is hard enough even using the correct terms. Programmers use the term "data declaration" when they really mean "data definition". They are not the same and that difference is not just semantic. Likewise, "Strings" and "strings" are not the same, but we do a little better job making that distinction.

Life would be easier for new students if we used the correct terms in everything we do, from writing and posting, to verbal communications. So, that data definition above is not an array of functions, and we should not pretend it is.

Can you help me then? I'm trying to make an array of 10 void functions.

econjack:
I've been using C for over 40 years and I have never seen an array of pointers to functions written this way.

What exactly are you referring to?

This:

void (*zn[num])(int pos);

?

But there's no other way to declare an array of pointers to functions in C! I mean, one can split it into several steps and make it more readable by introducing intermediate typedef names. But barring that (and the fact that the parameter name is optional) this is the only way to do it.

And if you are referring to this

z[0] = [](int pos)
{
  // code
};

then no wonder you have not seen it "using C for over 40 years". This is C++, not C.

econjack:
As to mangling terms, learning C is hard enough even using the correct terms. Programmers use the term "data declaration" when they really mean "data definition". They are not the same and that difference is not just semantic.

Um... There's a chance that you are misunderstanding something.

These terms are not mutually exclusive. Every definition is also a declaration at the same time. In those contexts where the distinction does not matter, it is preferable to use the term declaration (even if you are referring to a definition). The general rule is:

Use the term "declaration" whenever you can, use the term "definition" only when you really have to.

This is how the language specification itself does it.

econjack:
So, that data definition above is not an array of functions, and we should not pretend it is.

Duly noted.

bttshrbs:
Can you help me then? I'm trying to make an array of 10 void functions.

Neither C not C++ has such thing as "array of functions". It is not possible. What your code is using is an array of pointers to functions. And this is exactly what you need, judging by the rest of the code.

But you just said that your code compiles now. What's the problem then?

econjack:
I've been using C for over 40 years and I have never seen an array of pointers to functions written this way. As to mangling terms, learning C is hard enough even using the correct terms. Programmers use the term "data declaration" when they really mean "data definition". They are not the same and that difference is not just semantic. Likewise, "Strings" and "strings" are not the same, but we do a little better job making that distinction.

Life would be easier for new students if we used the correct terms in everything we do, from writing and posting, to verbal communications. So, that data definition above is not an array of functions, and we should not pretend it is.

lamda expression is new feature comes with c++14. That being said, I agree with you, the author just trying to be clever, but I think it's just dumb.

The confusing about strings vs Strings is that in OS environment, string class IS equivalent to Arduino String. When beginner trying to learn c++, they most often run into those topics that are intended for OS environment.

arduino_new:
lamda expression is new feature comes with c++14.

C++11, not C++14. Which is quite important because Arduino IDE uses C++11. Lambda expressions are available to us in Arduino IDE in their C++11 form.

Montmorency:
These terms are not mutually exclusive. Every definition is also a declaration at the same time. In those contexts where the distinction does not matter, it is preferable to use the term declaration (even if you are referring to a definition). The general rule is:

Use the term "declaration" whenever you can, use the term "definition" only when you really have to.

This is how the language specification itself does it.

Not correct. While it is true that every definition is a declaration, the reverse is NOT true. If it were, you wouldn't need the keyword extern. A data declaration is an attribute list that describes the characteristics of the data item (e.g., ID, type, scope, etc.). Use of the word extern or a function prototype are examples of data declarations. A data definition is also the same attribute list, but also results in memory being allocated for the item. Data declarations do NOT allocate memory.

When I said I've never seen code written like that before, I usually see an array of pointers to functions initialized with the name of the functions, not the actual code itself. However, since that's still going to resolve to an lvalue, I suppose it should work.

econjack:
Not correct.

What I said above is absolutely correct.

econjack:
While it is true that every definition is a declaration, the reverse is NOT true.

What??? But who said that the reverse is true?

econjack:
If it were, you wouldn't need the keyword extern. A data declaration is an attribute list that describes the characteristics of the data item (e.g., ID, type, scope, etc.). Use of the word extern or a function prototype are examples of data declarations. A data definition is also the same attribute list, but also results in memory being allocated for the item.

I don't understand why your are dumping all this here and how it is relevant. Nobody said that every declaration is a definition.

Just remember that "definitions" are subset of "declarations". Every definition is a declaration. Not every declaration is a definition.

And again, in contexts when it doesn't matter whether a given declaration is a definition (or not), people will use the term declaration. That is the accepted practice in C and C++ terminology.

econjack:
Data declarations do NOT allocate memory.

False!!!

All declarations is C/C++ are split into two kinds:

  1. The ones that ARE NOT definitions. We call them "mere declarations" or "non-defining declarations".
  2. The ones that ARE definitions . We call them "definitions", or "defining declarations".

So, your above quoted assertion is incorrect. There are data declarations that do not allocate memory, and there are data declarations that do. The latter are called "definitions".

econjack:
When I said I've never seen code written like that before, I usually see an array of pointers to functions initialized with the name of the functions, not the actual code itself. However, since that's still going to resolve to an lvalue, I suppose it should work.

That has nothing to do with "resolviong to lvalue". That has everything to do with C++ lambda-expressions and the fact that a capture-less lambda-expression is implicitly convertible to a plain function pointer.

@Montmorency, @arduino_new, and @econjack, stop with the childish pissing contest.

The next post will be from the original poster or will be helpful to the original poster. Good luck. Some of you three are going to need it.

I got help from another forum while you guys were fighting, but thanks anyway.

bttshrbs:
I got help from another forum while you guys were fighting, but thanks anyway.

We were "fighting" just to pass time, while waiting for you to finally explain what the problem is. But you apparently did not care much...