|
Hi,
i have a tool which generates some code, so i cannot place the include at the top of the file.
case ID_ONE:
if (id == 1)
{
#include "Func.h"
Func();
}
if (id == 2)
{
Func();
}
break;
I get the following error:
incompatible implicit declaration of function 'Func'
If i remove the #include then it compiles with a warning (implicit declaration). Is it not legal to #include in if statements?
|
|
|
|
|
You did not mention which line produced the error; I would guess the second one, which does not 'see' the include file. You need to move the #include statement outside the if clause.
|
|
|
|
|
This won't work.
Include statements are processed by the C/C++ preprocessor[^] which is executed as first build step before compilation. But the if condition is processed when your application is executed.
It is possible to use include statements somewhere inside the code. But then the file content must be valid code only (imagine what the statement does: It replaces the statement with the file content).
|
|
|
|
|
It is legal but probably doesn't do what is expected (by you).
Suppose "Func.h" is
double Func();
Then, what you get (after preprocessor pass) is:
case ID_ONE:
if (id == 1)
{
double Func();
Func(); }
if (id == 2)
{
Func(); }
|
|
|
|
|
elelont2 wrote: i have a tool which generates some code
I question that statement. Certainly the professional code generation tools that I have used allow for customization which would always include a way to provide includes.
If it an in-house tool then obviously the way to go would be to modify it.
However an alternative would be to create your own simple tool which does nothing but insert a header. It is probably possible to do this with existing tools and an appropriate command line script. Even simple file concatenation might be sufficient. Then once you have that methodology down modify your build to do that step after code generation but before the compile.
|
|
|
|
|
Hi,
i cannot figure this out:
typedef struct
{
int a;
int b;
} CARPIC;
const CARPIC const* CarPics[] =
{
&Audi,
&BMW,
&Bugatti,
}
void GetCarPicture(CARPIC** carPicture)
{
int carId= GetCarId(); *carPicture = CarPics[carId];
}
CARPIC* car;
GetCarPicture(&car);
I get the warning:
warning: assignment discards qualifiers from pointer target type
I tried to add the const keyword to the GetCarPicture function parameter but could not figure out where to add it. I need to get the pointer to the const car picture.
Regards.
|
|
|
|
|
This would make more sense:
typedef struct
{
int a;
int b;
} CARPIC;
CARPIC Audi = { 1, 2 };
CARPIC BMW = { 1, 2 };
CARPIC Bugatti = { 1, 2 };
CARPIC const* CarPics[] =
{
&Audi,
&BMW,
&Bugatti,
};
const CARPIC* GetCarPicture(int carId)
{
return CarPics[carId];
}
CARPIC const* car;
car = GetCarPicture(2);
|
|
|
|
|
It should be
void GetCarPicture(const CARPIC const * * carPicture)
{
}
const CARPIC const * car;
GetCarPicture(&car);
|
|
|
|
|
Thanks, worked great, will try to figure out what gets consted...
|
|
|
|
|
|
The two const s are duplicate. Both refer to the CARPIC value. Neither refers to the pointer.
You might also want to check out my comment to CPallinis response in this thread.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
These second const s don't appear to make sense: both refer to the CARPIC value, neither refers to the pointer holding the address. That's also what my compiler states (in a warning).
To give some examples:
const int *a; int const *a; const int const *a; int *const a; const int * const a;
See also http://cdecl.ridiculousfish.com/?q=const+int+*+const+*+a%3B[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
How do I recover what's left of a file that has been deleted but not completely over written?
Let's say the deleted file is 10mb
5 of those have been overwritten
I want to restore the remaining 5.
Thanks!
|
|
|
|
|
Use Google to find a free application to do it. It is a complex process and requires a detailed understanding of the filesystem where the file was created.
|
|
|
|
|
|
Hi all. I have a doubt: how ulSize data buffer size should be:
CString sValue;
ULONG ulSize = _MAX_PATH;
lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE*)sValue.GetBuffer(_MAX_PATH), &ulSize);
sValue.ReleaseBuffer();
or
CString sValue;
ULONG ulSize = _MAX_PATH * sizeof(TCHAR);
lRet = RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE*)sValue.GetBuffer(_MAX_PATH), &ulSize);
sValue.ReleaseBuffer();
I guess that ulSize should be _MAX_PATH * sizeof(TCHAR); like in the second code ... but I am not sure ... can you tell me how is right ?
Thank you.
modified 8-Apr-15 5:37am.
|
|
|
|
|
From MSDN RegQueryValueEx function[^]:
Quote: lpcbData [in, out, optional]
A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. So it must be the second version.
|
|
|
|
|
|
|
hey.....i have searched alot about c graphics and till now don't get any helpful information.
so i want to know some sites which can provide data about c graphics...basically i want to learn this....so do me a favor
|
|
|
|
|
Do yourself a favour and study the documentation[^]. Google will find you some alternatives.
|
|
|
|
|
The C programming language doesn't provide, by itself, functions for graphics. You have to use, in your application, the graphics API your system provides.
|
|
|
|
|
As pointed out, C and C++ do not (yet) have built-in graphics capabilities. There are plenty of libraries for that purpose however, and plenty of articles offering advice on how to use them. What library to use strongly depends on the purpose you have in mind. I therfore suggest you feed the search engines of your choice with the keywords, "C", "Graphics programming" and maybe a keyword or two describing the application you have in mind.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Because it is difficult and wastes time for modifying the controls position in xml file directly.
Is anyone know how to design a good one as visual studio that cat drag and drop controls?
|
|
|
|