Author Topic: Errors and warnings  (Read 11861 times)

Offline Marcel

  • Single posting newcomer
  • *
  • Posts: 9
Errors and warnings
« on: January 25, 2008, 07:50:41 pm »
I have Errors and warnings with Code::blocks. On MS VC++ 2005 EE everything's fine.
Im not good at speaking English...
Code
-------------- Build: Debug in Timer ---------------

Compiling: main.cpp
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Errors and warnings
« Reply #1 on: January 25, 2008, 08:30:31 pm »
I have Errors and warnings with Code::blocks. On MS VC++ 2005 EE everything's fine.
You won't get any useful answer with such less information.
What C::B version? What compiler (version)? What OS? What application? Provide code. Provide the compile full log (see my sig)...
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Marcel

  • Single posting newcomer
  • *
  • Posts: 9
Re: Errors and warnings
« Reply #2 on: January 25, 2008, 08:46:17 pm »
I Use on Windows Code::Blocks with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
Code
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings

My Code:
Code
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
int Auswahl;
int Zeit;

do
{
cout << "1 für Sekunden" << endl;
cout << "2 für Minuten" << endl;
cout << "3 Hilfe" << endl;
cout << "4 um zu Beenden" << endl;
cin >> Auswahl;
cout << endl;

switch (Auswahl)
{
case (1):
{
cout << "Gib die Zeit in Sekunden ein: ";
cin >> Zeit;
for (Zeit; Zeit > 1; Zeit--)
{
cout << "Noch " << Zeit << " Sekunden" << endl;
Sleep (1000);
}
if (Zeit == 1)
cout << "Noch " << Zeit << " Sekunde" << endl;
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (2):
{
cout << "Gib die Zeit in Minuten ein: ";
cin >> Zeit;
if (Zeit > 1)
{
for (Zeit; Zeit >= 1; Zeit--)
{
cout << "Noch " << Zeit << " Minuten" << endl;
Sleep (60000);
}
}
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (3):
{
cout << "Das ist ein Programm, der die Zeit bis zum Ablaufen der Zeit zählt. Wenn die Zeit abgelaufen ist benachrichtigt das Programm sie mit einem Ton." << endl;
cout << endl;
} break;
default:
cout << "Falsche Eingabe!" << endl;
}
} while (Auswahl != 4);
return 0;
}
« Last Edit: January 25, 2008, 08:51:39 pm by Marcel »

Offline polygon7

  • Multiple posting newcomer
  • *
  • Posts: 104
    • Home site
Re: Errors and warnings
« Reply #3 on: January 25, 2008, 08:58:31 pm »
I Use on Windows Code::Blocks RC2 with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
Code
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings

My Code:
Code
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);


Hi,
remove "L" from all strings in PlaySound (...) calls.

P.S. Also I think that code
Code
for (Zeit; Zeit > 1; Zeit--)
{
}
should be something like that
Code
for (int counter = Zeit; counter > 1; counter--)
{
    cout << counter;
}
best regards,
p7
 Free open source UML modeling tool: ArgoUML

Offline Marcel

  • Single posting newcomer
  • *
  • Posts: 9
Re: Errors and warnings
« Reply #4 on: January 25, 2008, 09:06:40 pm »
Thanks.
Code
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\Timer.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/C++/Timer/main.cpp:32: undefined reference to `PlaySoundA@12'
C:/C++/Timer/main.cpp:56: undefined reference to `PlaySoundA@12'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings

Do you know what's wrong here?

I removed the L and I changend the fors to
Code
for (int i = Zeit; i > 1; i--)

Is it standard to initialize the variables in the loops?

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Errors and warnings
« Reply #5 on: January 25, 2008, 09:27:08 pm »
Is it standard to initialize the variables in the loops?

On C++ is possible, but not on ANSI C

Offline polygon7

  • Multiple posting newcomer
  • *
  • Posts: 104
    • Home site
Re: Errors and warnings
« Reply #6 on: January 25, 2008, 09:28:30 pm »
Thanks.
Code
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\Timer.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/C++/Timer/main.cpp:32: undefined reference to `PlaySoundA@12'
C:/C++/Timer/main.cpp:56: undefined reference to `PlaySoundA@12'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings

Do you know what's wrong here?
You should add a lib to linker options (but I don't remember which has PlaySound, probably winmm or user32).
best regards,
p7
 Free open source UML modeling tool: ArgoUML

Offline Marcel

  • Single posting newcomer
  • *
  • Posts: 9
Re: Errors and warnings
« Reply #7 on: January 25, 2008, 09:32:09 pm »
winmm.lib. But why is in Code::Blocks the winmm.lib now libwinmm.a? MS VC++ 2005 EE was easier... x)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Errors and warnings
« Reply #8 on: January 25, 2008, 09:32:15 pm »
Is it standard to initialize the variables in the loops?

Not necessarily.

If you want to use the last value of the loop-variable outside the loop (like in your "case (1):",  you need to declare the variable outside the loop.
A variable declared in the for-loop's head is only visible inside this loop.

Some very old or broken compilers might ignore that (there might even be a compiler-switch to do so), but it's not standard conform and not reliable.

Offline darthdespotism

  • Almost regular
  • **
  • Posts: 163
    • Coder's Nemesis
Re: Errors and warnings
« Reply #9 on: January 25, 2008, 10:05:59 pm »
winmm.lib. But why is in Code::Blocks the winmm.lib now libwinmm.a? MS VC++ 2005 EE was easier... x)

You can use MS Toolkit compiler instead of MinGW. I guess there was some #pragma coment() used for Linking which is only supported by VS VC.

In Fact it will be libwinmm.a for MinGW, linked by -lwinmm (gcc adds the lib and .a automatically ;) )

Offline Marcel

  • Single posting newcomer
  • *
  • Posts: 9
Re: Errors and warnings
« Reply #10 on: January 26, 2008, 07:23:04 am »
Okay thanks at all :)
Yes in VC++ it was #pragma comment (lib, "winmm.lib") ;)