What would this " }; " represent... OR What is this }; doing in my code....

Using Arduino, for the ESP32, I am trying to make sense of the ESP-IDF… Now in the following code, for the pulse counter, the example uses this }; … Can the LINE following that be changed to an

" if (pcnt_unit_config(&pcnt_config) == ESP_OK)
{
stuff
}

or what is the }; telling the code to do.??

The code DOES work but I’m not sure just how to read it…
CODE:

pcnt_config_t pcnt_config =
{

pulsePin, // Pulse input gpio_num, if you want to use gpio16, pulse_gpio_num = 16
PCNT_PIN_NOT_USED, // Control signal input gpio_num, a negative value will be ignored
PCNT_MODE_KEEP, // PCNT low control mode
PCNT_MODE_KEEP, // PCNT high control mode
PCNT_COUNT_INC, // PCNT positive edge count mode
PCNT_COUNT_DIS, // PCNT negative edge count mode
PCNT_H_LIM_VAL, // Maximum counter value
PCNT_L_LIM_VAL, // Minimum counter value
PCNT_TEST_UNIT, // PCNT unit number
PCNT_CHANNEL_0, // the PCNT channel

};

if(pcnt_unit_config(&pcnt_config) == ESP_OK) //init unit

/Configure input filter value/
pcnt_set_filter_value(PCNT_TEST_UNIT, 100);
/Enable input filter/
pcnt_filter_enable(PCNT_TEST_UNIT);
/Set value for watch point thresh1/
pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
/Enable watch point event of thresh1/
//pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_1);
pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_1);
/Set value for watch point thresh0/
pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
/Enable watch point event of thresh0/
//pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_0);
pcnt_event_disable(PCNT_TEST_UNIT, PCNT_EVT_THRES_0);
/Enable watch point event of h_lim/
//pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_H_LIM);
pcnt_event_disable(PCNT_TEST_UNIT, PCNT_EVT_H_LIM);
/Enable watch point event of l_lim/
//pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_L_LIM);
pcnt_event_disable(PCNT_TEST_UNIT, PCNT_EVT_L_LIM);
/Enable watch point event of zero/
//pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_ZERO);
pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_ZERO);
/Pause counter/
pcnt_counter_pause(PCNT_TEST_UNIT);
/Reset counter value/
pcnt_counter_clear(PCNT_TEST_UNIT);
/Register ISR handler/
///// pcnt_isr_register(pcnt_example_intr_handler, NULL, 0, NULL);
/Enable interrupt for PCNT unit/
pcnt_intr_enable(PCNT_TEST_UNIT);
/Resume counting/
pcnt_counter_resume(PCNT_TEST_UNIT);
}

or what is the }; telling the code to do.??

That is like asking what the ll in that sentence is doing.

You need to look at the entire statement. If you do, it is perfectly obvious what the closing curly brace closes, and it is perfectly obvious that the semicolon is needed to end the statement.

Can the LINE following that be changed to an

Can which of the lines you improperly posted be changed?

First time seeing }; Usually it's just }

LandonW:
First time seeing }; Usually it's just }

int array[3] = {0, 0, 0 };

The ; is MANDATORY.

The "}" ends the list of initializers and the ";" ends the declaration statement. Since the declaration is not inside a function, the next statement must also be a declaration of a variable or function.

{} are used for two purposes, to define blocks, like in if statements and the like (doesn't need a ; after the }), and when declaring arrays (which is a statement, and requires a ; at the end)

DrAzzy:
{} are used for two purposes, to define blocks, like in if statements and the like (doesn't need a ; after the }), and when declaring arrays (which is a statement, and requires a ; at the end)

Also class definitions where you have to have the semicolon at the end. That one bites me a lot.

Delta_G:
Also class definitions where you have to have the semicolon at the end. That one bites me a lot.

...and the class's loose-tongued sibling, the struct.

LandonW:
First time seeing }; Usually it's just }

A statement ends in a semicolon, a code block (in braces) does not,

However this is a statement that has a data initializer in it, which also uses {}, but is not a
code block at all. The statement needs a ; at the end.

So be aware of the two completely different uses of {} in C, to delimit a code block, and
to represent a list of data items (such as an array, struct, or class definition)

Well, Thank you all for your response,,, I think "johnwasser" and "MarkT" is right in the explanation... I knew It was something more than USUAL, as the code uses 3 brackets and compiles,,, and you can't seem to re-wight the code any other way without errors.. I tried to put everything after it, in an if statement but that didn't work, so,,, the }; in a ESP-IDF CONFIG = tells the compiler, that the first part { is declaration stuff }; and then more declarations}..
I come from decades with microchip and just haven't run into this before... Thanks all..

so,,, the }; in a ESP-IDF CONFIG = tells the compiler, that the first part { is declaration stuff }; and then more declarations}..

That whole section before the if statement is defining an object of type pcnt_config_t named pcnt_config and all the stuff between the { and } are the initializers for it. It's perfectly normal syntax you're probably just being thrown off by the fact that it is broken into multiple lines.

I don't know what library or code that came from so I have no idea what that object is or does. But that whole thing is really just one long line of code defining an object.

And don't try to put the } and the ; together. They don't mean anything together. The ; is the normal end of a statement and the } just happens to be the last character in that statement. It's not any different from any other line of code that ends in a ;

johnwasser:
Since the declaration is not inside a function, the next statement must also be a declaration of a variable or function.

When he said this it wasn’t about the } or the ; He was telling you why you can’t have an if statement there. An if statement would have to be inside of a function. And this is not.

At Paul and Mark... thanks. Learn something new everyday.

Don_Warr:
the }; in a ESP-IDF CONFIG = tells the compiler, that the first part { is declaration stuff };

It's the '=' in the declaration that tells the compiler that the next thing is an initializer. The '{' after that tells the compiler that everything up to the matching '}' is a list of initializers. The ';' after the matching '}' signals the end of the declaration. If there was a ',' instead of a ';' it would tell the compiler that the next thing is another identifier to be declared the same way. For example:

int list1[2] = {1, 2}, counter = 2, seven = 7;

'list' is an array of two integers.
'counter' is an integer.
'seven' is an integer.