Can't use constexpr function in static_assert - c++11

tell me, please, why I can't use my constexpr recursive function to static_assert if string contains needed count of symbols? Constexpr function supposed to be a constant value, but VS2015 compiller tells me that expression did not evaluate to a constant (error C2131).
constexpr const char* GetRequestStr = "GETVARS:_local_=I,I..8:1-1;NI,NI..8:1-1";
constexpr unsigned RequestedVars(const char* str, unsigned cnt=0){
return str[0] == 0 ? cnt+1 : RequestedVars(str+1, str[0] == ';' ? ++cnt : cnt);
};
static_assert(RequestedVars(GetRequestStr) == 2, "Must be 2"); // C2131 here
the result (translated into English):
1> d: \ cprojects \ logo \ exchlogo.h (43): error C2131: expression not defined by constant
1> d: \ cprojects \ logo \ exchlogo.h (43): note: the failure was caused by parsing an assignment operation
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 26, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 25, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 24, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 23, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 22, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: skipped intermediate calls: 16 (/ constexpr: backtrace <NUMBER>)
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 5, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 4, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 3, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 2, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (43): note: when calculating "RequestedVars ((" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 ") + 1, 0)"
1> d: \ cprojects \ logo \ exchlogo.h (45): note: when calculating "RequestedVars (" GETVARS: _local_ = I, I..8: 1-1; NI, NI..8: 1-1 " , 0) "
1> d: \ cprojects \ logo \ exchlogo.h (45): error C2131: expression not defined by constant
1> d: \ cprojects \ logo \ exchlogo.h (43): note: the failure was caused by parsing an assignment operation

Related

How to set a flag `/LFSM:n[KMG]` with robocopy: `Invalid Parameter #8 : "/LFSM:n"`

I can't find where I go wrong with the / LFSM: n [KMG] flag to robocopy. I try to set a floor level at 100 MB. Error I'm getting: ERROR : Invalid Parameter #8 : "/LFSM:n"
I tried:
robocopy "C: \ Users \ test" "C: \ Users \ b2b \ Desktop \ test" / E / XC / XO / V / TEE / LFSM: n M: 100
robocopy "C: \ Users \ test" "C: \ Users \ b2b \ Desktop \ test" / E / XC / XO / V / TEE / LFSM: n [M: 100]
robocopy "C: \ Users \ test" "C: \ Users \ b2b \ Desktop \ test" / E / XC / XO / V / TEE / LFSM: n [, M: 100,]
robocopy "C: \ Users \ test" "C: \ Users \ b2b \ Desktop \ test" / E / XC / XO / V / TEE / LFSM: n [, 100,]
As Mathias R. Jessen said, the error was simple. n in /LFSM:n[KMG] points out where should be a number posted. So for:
1 Giga: /LFSM:1G
1 Mega: /LFSM:1M
1 Kilo: /LFSM:1K

Can't add reg expression for a #define in ctags

I can't figure out how to make ctags detect the __mrs_s definition. It doesn't add the search pattern so I can't find it in vi.
$cat /tmp/qq.h
int test(int i)
{
printf("Hello!");
return 0;
}
#define __mrs_s(v, r) \
DEFINE_MRS_S \
" mrs_s " v ", " __stringify(r) "\n" \
UNDEFINE_MRS_S
$ctags --regex-C++='/^#define \([a-zA-Z_0-9]+\)([a-zA-Z,\ ]+)[\t ]+/\1/d/' -o - /tmp/qq.h
__mrs_s /tmp/qq.h 7;" d
test /tmp/qq.h /^int test(int i)$/;" f
Use --excmd=pattern option like:
[root#localhost ~]# cat /tmp/qq.h
int test(int i)
{
printf("Hello!");
return 0;
}
#define __mrs_s(v, r) \
DEFINE_MRS_S \
" mrs_s " v ", " __stringify(r) "\n" \
UNDEFINE_MRS_S
[root#localhost ~]# ctags --excmd=pattern -o - /tmp/qq.h
__mrs_s /tmp/qq.h /^#define __mrs_s(/;" d
test /tmp/qq.h /^int test(int i)$/;" f

What does the root `CompoundStm` for the following source `stm1;stm2;stm3` have 2 child statements

I'm reading Modern Compiler Implementation in Java and the following simple source program code is shown:
a := 5+3; b := (print(a, a-1), 10*a); print(b)
The tree representation of the program looks like this:
CompoundStm
/ \
/ \
a := 5+3 b := (print(a, a-1), 10*a); print(b)
AssignStm CompoundStm
/ \ / \
/ \ / \
a OpExp AssignStm PrintStm
/ \
b EsecExp
But I expected it to be like this:
CompoundStm
/ | \
/ | \
a := 5+3 b := (pr...), 10*a) print(b)
AssignStm AssignStm PrintStm
/ \ / \
/ \ / \
a OpExp b EsecExp
What does the first CompoundStm have 2 children instead of 3? Is it because CompoundStm can only have 2 children?

improper matrix print out latex

using Latex to print out a Matrix , I noticed I can not place the numbers under each other correctly
here is the code, I really appreciate your help
\begin{center}
$ABD=
\begin{bmatrix}
12610207.7\quad 5695754.3\quad 0\quad 0\quad 0\quad 0 \\
5695754.3\quad 10737818.8\quad 0\quad 0\quad 0\quad 0 \\
0\quad 0\quad 2800468.2\quad 0\quad 0\quad 0\\
0\quad 0\quad 0\quad 37.3\quad 125.08\quad 0.12\\
0\quad 0\quad 0\quad 125.08\quad 0.24\quad 0\\
0\quad 0\quad 0\quad 0\quad 0\quad 0.12
\end{bmatrix}
\end{center}
$
\begin{equation} \label{10}
\end{equation}
\end{center}
Matrix (and other tabular or array) constructions use & to denote the column delineation, not \quad:
\documentclass{article}
\usepackage{amsmath,siunitx}
\begin{document}
Using \verb|bmatrix|:
\[
ABD =
\begin{bmatrix}
12610207.7 & 5695754.3 & 0 & 0 & 0 & 0 \\
5695754.3 & 10737818.8 & 0 & 0 & 0 & 0 \\
0 & 0 & 2800468.2 & 0 & 0 & 0 \\
0 & 0 & 0 & 37.3 & 125.08 & 0.12 \\
0 & 0 & 0 & 125.08 & 0.24 & 0 \\
0 & 0 & 0 & 0 & 0 & 0.12
\end{bmatrix}
\]
Using \verb|array|:
\[
ABD =
\left[\begin{array}{#{}
S[table-format=9.1]
S[table-format=9.1]
S[table-format=7.1]
S[table-format=3.2]
S[table-format=3.2]
S[table-format=1.2]#{}}
12610207.7 & 5695754.3 & 0 & 0 & 0 & 0 \\
5695754.3 & 10737818.8 & 0 & 0 & 0 & 0 \\
0 & 0 & 2800468.2 & 0 & 0 & 0 \\
0 & 0 & 0 & 37.3 & 125.08 & 0.12 \\
0 & 0 & 0 & 125.08 & 0.24 & 0 \\
0 & 0 & 0 & 0 & 0 & 0.12
\end{array}\right]
\]
With bmatrix you don't have to specify the number of columns. However, there is a limit, but this can be extended.
siunitx was added to align the columns inside the array in a specific table-format way. Using a column specification #{}*{6}{c}#{} would have worked to produce a similar output as bmatrix.

How solve this errors in avrstudio

what can i do with this errors?
#ifndef WS2811_h
#define WS2811_h
#include <avr/io.h>
#include <util/delay.h>
#include <WS2811.h>
Error 1 unterminated #ifndef
typedef struct __attribute__ ((__packed__)) {
uint8_t r;
uint8_t g;
uint8_t b;
} RGB_t;
Error 2 expected ':', ',', ';', '}' or '__attribute__' before 'r'
please help me! thanks
thanks for your help but it not worked!!!
the main code is here:
/*
* WS2811 RGB LED driver.
*/
#include <stdio.h>
#include <stdint.h>
#ifndef WS2811_h
#define WS2811_h
#endif
#include <WS2811.h>
// RGB value structure.
typedef struct __attribute__ ((__packed__)) {
uint8_t r;
uint8_t g;
uint8_t b;
} RGB_t;
#ifndef ARRAYLEN
#define ARRAYLEN(A) (sizeof(A) / sizeof(A[0]))
#endif
/*
* Inline asm macro to output 24-bit RGB value in (G,R,B) order, MSBit first.
* 0 bits are 250ns hi, 1000ns lo, 1 bits are 1000ns hi, 250ns lo.
* r18 = red byte to be output
* r19 = green byte to be output
* r20 = blue byte to be output
* r26 = saved SREG
* r27 = inner loop counter
*/
#define WS2811(PORT, PIN, RGB, LEN) \
asm volatile( \
/* initialise */ \
" cp %A[len], r1 ; check len > 0, return immediately if it is\n" \
" cpc %B[len], r1\n" \
" brne 1f\n" \
" rjmp 16f\n" \
"1: ld r18, Z+ ; load in first red byte to be output\n" \
" ld r19, Z+ ; load in first green byte to be output\n" \
" ld r20, Z+ ; load in first blue byte to be output\n" \
" ldi r27, 8 ; load inner loop counter\n" \
" in r26, __SREG__ ; timing-critical, so no interrupts\n" \
" cli\n" \
/* green - loop over 8 bits */ \
"2: sbi %[port], %[pin] ; pin lo -> hi\n" \
" sbrc r19, 7 ; test hi bit clear\n" \
" rjmp 3f ; true, skip pin hi -> lo\n" \
" cbi %[port], %[pin] ; false, pin hi -> lo\n" \
"3: sbrc r19, 7 ; equalise delay of both code paths\n" \
" rjmp 4f\n" \
"4: nop ; pulse timing delay\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" lsl r19 ; shift to next bit\n" \
" dec r27 ; decrement loop counter\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" brne 2b\n ; loop if required\n" \
" ldi r27, 7 ; reload inner loop counter\n" \
/* red - loop over first 7 bits */ \
"5: sbi %[port], %[pin] ; pin lo -> hi\n" \
" sbrc r18, 7 ; test hi bit clear\n" \
" rjmp 6f ; true, skip pin hi -> lo\n" \
" cbi %[port], %[pin] ; false, pin hi -> lo\n" \
"6: sbrc r18, 7 ; equalise delay of both code paths\n" \
" rjmp 7f\n" \
"7: nop ; pulse timing delay\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" lsl r18 ; shift to next bit\n" \
" dec r27 ; decrement inner loop counter\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" brne 5b ; inner loop, if required\n" \
" nop ; equalise delay of both code paths\n" \
/* red, 8th bit - output & fetch next values */ \
" sbi %[port], %[pin] ; pin lo -> hi\n" \
" sbrc r18, 7 ; test hi bit clear\n" \
" rjmp 8f ; true, skip pin hi -> lo\n" \
" cbi %[port], %[pin] ; false, pin hi -> lo\n" \
"8: sbrc r18, 7 ; equalise delay of both code paths\n" \
" rjmp 9f\n" \
"9: nop ; pulse timing delay\n" \
" nop\n" \
" nop\n" \
" ld r18, Z+ ; load next red byte\n" \
" ld r19, Z+ ; load next green byte\n" \
" ldi r27, 7 ; reload inner loop counter\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" nop ; pulse timing delay\n" \
" nop\n" \
/* blue - loop over first 7 bits */ \
"10: sbi %[port], %[pin] ; pin lo -> hi\n" \
" sbrc r20, 7 ; test hi bit clear\n" \
" rjmp 11f ; true, skip pin hi -> lo\n" \
" cbi %[port], %[pin] ; false, pin hi -> lo\n" \
"11: sbrc r20, 7 ; equalise delay of both code paths\n" \
" rjmp 12f\n" \
"12: nop ; pulse timing delay\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" nop\n" \
" lsl r20 ; shift to next bit\n" \
" dec r27 ; decrement inner loop counter\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" brne 10b ; inner loop, if required\n" \
" nop ; equalise delay of both code paths\n" \
/* blue, 8th bit - output & handle outer loop */ \
" sbi %[port], %[pin] ; pin lo -> hi\n" \
" sbrc r20, 7 ; test hi bit clear\n" \
" rjmp 13f ; true, skip pin hi -> lo\n" \
" cbi %[port], %[pin] ; false, pin hi -> lo\n" \
"13: sbrc r20, 7 ; equalise delay of both code paths\n" \
" rjmp 14f\n" \
"14: nop ; pulse timing delay\n" \
" nop\n" \
" ldi r27, 8 ; reload inner loop counter\n" \
" sbiw %A[len], 1 ; decrement outer loop counter\n" \
" breq 15f ; exit outer loop if zero\n" \
" ld r20, Z+ ; load in next blue byte\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" rjmp 2b ; outer loop, if required\n" \
"15: nop ; pulse timing delay\n" \
" cbi %[port], %[pin] ; pin hi -> lo\n" \
" nop ; pulse timing delay\n" \
" nop\n" \
" out __SREG__, r26 ; reenable interrupts\n" \
"16:\n" \
: \
: [rgb] "z" (RGB), \
[len] "w" (LEN), \
[port] "I" (_SFR_IO_ADDR(PORT)), \
[pin] "I" (PIN) \
: "r18", "r19", "r20", "r26", "r27", "cc", "memory" \
)
/*
* Define a C function to wrap the inline WS2811 macro for a given port and pin.
*/
#define DEFINE_WS2811_FN(NAME, PORT, PIN) \
extern void NAME(const RGB_t *rgb, uint16_t len) __attribute__((noinline)); \
void NAME(const RGB_t *rgb, uint16_t len) { WS2811(PORT, PIN, rgb, len); }
#endif /* WS2811_h */
/*
* Copyright 2012 Alan Burlison, alan#bleaklow.com. All rights reserved.
* Use is subject to license terms.
*
* Demo of the WS2811 driver, driving 3 pixels.
*/
#include <avr/io.h>
#include <util/delay.h>
#define BIT(B) (0x01 << (uint8_t)(B))
#define SET_BIT_HI(V, B) (V) |= (uint8_t)BIT(B)
#define SET_BIT_LO(V, B) (V) &= (uint8_t)~BIT(B)
#define PAUSE 1000 // msec
#define DELAY 10 // msec
// Define the output function, using pin 0 on port b.
DEFINE_WS2811_FN(WS2811RGB, PORTB, 0)
// Drive the three pixels in an infinit loop.
void threepixeldemo(void)
{
// Configure pin for output.
SET_BIT_HI(DDRB, 0);
SET_BIT_LO(PORTB, 0);
// off->red, off->green, off->blue
RGB_t rgb[3] = {{0,0,0},{0,0,0},{0,0,0}};
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(PAUSE);
for (int i = 0; i < 255; i++) {
rgb[0].r += 1;
rgb[1].g += 1;
rgb[2].b += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// loop forever.
for (;;) {
// red->yellow, green->cyan, blue->magenta
for (int i = 0; i < 255; i++) {
rgb[0].g += 1;
rgb[1].b += 1;
rgb[2].r += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// yellow->green, cyan->blue, magenta->white
for (int i = 0; i < 255; i++) {
rgb[0].r -= 1;
rgb[1].g -= 1;
rgb[2].g += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// green->cyan, blue->magenta, white->off
for (int i = 0; i < 255; i++) {
rgb[0].b += 1;
rgb[1].r += 1;
rgb[2].r -= 1;
rgb[2].g -= 1;
rgb[2].b -= 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// cyan->blue, magenta->white, off->red
for (int i = 0; i < 255; i++) {
rgb[0].g -= 1;
rgb[1].g += 1;
rgb[2].r += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// blue->magenta, white->off, red->yellow
for (int i = 0; i < 255; i++) {
rgb[0].r += 1;
rgb[1].r -= 1;
rgb[1].g -= 1;
rgb[1].b -= 1;
rgb[2].g += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// magenta->white, off->red, yellow->green
for (int i = 0; i < 255; i++) {
rgb[0].g += 1;
rgb[1].r += 1;
rgb[2].r -= 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// white->off, red->yellow, green->cyan
for (int i = 0; i < 255; i++) {
rgb[0].r -= 1;
rgb[0].g -= 1;
rgb[0].b -= 1;
rgb[1].g += 1;
rgb[2].b += 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
// off->red, yellow->green, cyan->blue
for (int i = 0; i < 255; i++) {
rgb[0].r += 1;
rgb[1].r -= 1;
rgb[2].g -= 1;
WS2811RGB(rgb, ARRAYLEN(rgb));
_delay_ms(DELAY);
}
}
}
Add #include <stdint.h> to bring in the definition of uint8_t.
#ifndef WS2811_h
#define WS2811_h
/** missing an #endif here, (most likely) */
#include <avr/io.h>
#include <util/delay.h>
#include <WS2811.h>
The missing endif causes errors further down.
expected ':', ',', ';', '}' or '__attribute__' before 'r'
This type of error is usually caused by some earlier error, often with the #includes. You missed an #endif, but it can also happen when files include each other improperly. As with any macro errors, they are difficult to track down.

Resources