error: expected an identifier [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to build my code but getting error in below lines in header file
sample.h
1 #ifndef FORMAT_STRING_H
2 #define FORMAT_STRING_H
3
4 #define FORMAT_STR( ovr, x, y, ... ) \
5 { \
6 char buf[100]; memset(buf, 0, 100);\
7 using namespace std; \
8 snprintf(buf, 99, __VA_ARGS__); \
9 ovr->drawStr( x, y, buf );\
10 }
11 #endif //FORMAT_STRING_H
and getting error at line 4 error: expected an identifier .
I am not able to understand what is the problem exactly in mentioned line .
I am using Ti DSP C6000 Code Generation Tools 7.3.0B3 compiler .
Compiling C++ code .

It seems your compiler does not support a function-like macro with variable number of arguments.
It is very simple to check this. Write for example
#define FORMAT_STR( ovr, x, y, ... )\
{\
}
and do not call it in the code. If the compiler will issue the same error then indeed it does not support such macros.

Related

Getting initializer-string for char array is too long. Is this a compiler error? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
static_assert(0<decltype(AType::Id)::MaxIdLen);
using __type = char[decltype(AType::Id):: MaxIdLen + 10000];
[[maybe_unused]] __type aa = ""; //error initializer-string for char array is too long
I am getting this weird compiler error saying the initializer string is too long. But it is actually not. The first static_assert passed.
Has anyone seen such an issue before? I am using clang.
... compiler error saying the initializer string is too long. But it is actually not.
The compiler is not telling you that the string is too long to init aa. It's telling you that it's more data than it can handle, presumably because decltype(AType::Id)::MaxIdLen is a large value.
The compiler doesn't just store the string literal in the character array. It initialises the entire character array by using the string literal as a prefix, and padding the rest with zeros.

cannot convert argument 1 from const wchar_t[9] to wchar_t [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
FULL CODE
I am following this tutorial and have followed step by step from his tutorial and when he came to episode 8 I got an error in Level1.h.
void Level1::Load()
{
sprites = new SpriteSheet(L"test.png", gfx);
}
ERROR
'SpriteSheet::SpriteSheet(const SpriteSheet &)': cannot convert argument 1 from 'const wchar_t [9]' to 'wchar_t *'
I have written both Level1.h, Spritesheet.cpp and Spritesheet.h more than twice, tried to take away the "L" before the "test.png".
Also want to point out that I have Visual Studio 2017.
I would love you if you can solve my problem <3.
Full code
Literal strings in C++ are really constant arrays of the character type, that's why L"test.png" is mentioned as the typeconst wchar_t [9] (the size is 9 to fit the terminator).
As any other array it can decay to a pointer to its first element, and this pointer have the type const wchar_t*.
Note the use of const in the types above... That's what's missing in your constructor argument. It needs to be
SpriteSheet(const wchar_t* filename, Graphics*gfx);
// ^^^^^
// Note the const here

Use Cout to create asterisk shapes (No Loops) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, I've looked at other solutions with a similar problem to mine, but they all use loops to display the characters. What's required of me is to create 3 shapes using asterisks in C++. That's not so much the issue for me as actually getting them to display in the debugging window, instead of receiving a build error. Below is a test code of simply attempting to output the asterisk symbol:
#include<iostream>
using namespace std;
int main{
cout << "*" << endl
}
resulting in the following block of errors (file location redundancy omitted):
1>source.cpp(10): error C2440: 'initializing': cannot convert from'std::basic_ostream>' to 'int'
1> source.cpp(10): note: Reason: cannot convert from 'std::basic_ostream>' to 'int'
1> source.cpp(10): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>source.cpp(11): fatal error C1004: unexpected end-of-file found
I can only use programming based on what we've already learned, so I need to do these with nothing more than some basic cout statements.
main() is missing parentheses, and the statement is missing a semicolon.
int main() {
// ^^
cout << "*" << endl;
// ^
}

compare strings with strcmp function works different [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm comparing two strings with strcmp in the following manner:
long t=1011;
char tc[10], tcr[10];
ltoa(t,tc,10);
cout<<tc<<endl; //prints 1011
strcpy(tcr, strrev(tc));
cout<<tcr<<endl; //prints 1101
cout<<strcmp(tc,tcr);
This gives me a result of 0, which indicates that the strings are equal. However, when I try:
cout<<strcmp("1011", "1101"); // prints -1 thats okay
I get the expected value of -1. What's am I doing wrong? I am using devc++ compiler version 4.9.9.2
It depends on how function strrev is defined, If it reverses the argument in place then the result is expected because tc was reversed.
For example function strrev can be declared the following way
char * strrev( char *s );
and the return value and the value of the argument will be equal.
Take into account that strrev is not a standard function.
If you change your code like so:
long t=1011;
char tc[10], tcr[10];
ltoa(t,tc,10);
strcpy(tcr, strrev(tc));
cout<<tc<<endl;
cout<<tcr<<endl;
cout<<strcmp(tc,tcr);
then you'll see that tc and tcr are the same. strrev reverses the input string in place, and 1101 is printed twice.

I don't understand the working of the following Macro [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
What is the mathematical equivalent equation of following Macro
#define SQ(a) (a*a )
int answer SQ(2 + 3 );
Output is 11 for this case
and for
int answer SQ(2 + 4);
is 14 I can't figure out the equation from outputs.
The macro you defined lacks brackets to keep the arithmetic working as you want. Remember preprocessor macros are doing text replacement solely. So what you'll get from calling it as you shown expands to
int answer (2 + 4 * 2 + 4);
and according operator precedence the result is 14.
Write your macro as
#define SQ(a) ((a)*(a))
to get the result you expected.
SQ(2 + 4) expands to 2+4*2+4 = 14 because you have not used brackets in your macro. It is a generic macro pitfall for newcomers as macros are not quite safe in this respect as they are just processed by the preprocessor as raw string.
You should write something like this:
#define SQ(a) ((a)*(a))
and that will expand to: (2+4)*(2+4) = 36.
The same logic holds true If you replace 4 with 3, you will get to the 11, and with the corrected macro 25.
That being said, you really should not initialize an integer like that. The general way is to use explicit assignment.