Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Komisches Problem mit einer For-Schleife

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich hab hier mal ein ganz komisches Problem:

Folgendes C-Minimalprogramm


void main()

{

	for(int i = 0; i < 1; i++)

	{


	}

}

wirft folgende Fehler in Visual Studio 2010 Warning 6 warning C4552: '<' : operator has no effect; expected operator with side-effect d:\workspace visual studio\projects\a37a\a37a.c 5 Error 1 error C2143: syntax error : missing ';' before 'type' d:\workspace visual studio\projects\a37a\a37a.c 5 Error 2 error C2143: syntax error : missing ';' before 'type' d:\workspace visual studio\projects\a37a\a37a.c 5 Error 4 error C2143: syntax error : missing ';' before 'type' d:\workspace visual studio\projects\a37a\a37a.c 5 Error 9 error C2143: syntax error : missing ';' before '{' d:\workspace visual studio\projects\a37a\a37a.c 6 Error 3 error C2143: syntax error : missing ')' before 'type' d:\workspace visual studio\projects\a37a\a37a.c 5 Error 5 error C2065: 'i' : undeclared identifier d:\workspace visual studio\projects\a37a\a37a.c 5 Error 7 error C2065: 'i' : undeclared identifier d:\workspace visual studio\projects\a37a\a37a.c 5 Error 8 error C2059: syntax error : ')' d:\workspace visual studio\projects\a37a\a37a.c 5 Und komischerweise wird folgendes Programm fehlerfrei kompiliert

void main()

{

	int i;

	for(i = 0; i < 1; i++)

	{


	}

}

Hat jemand irgendeine Ahnung woran das liegen könnte?

Hat jemand irgendeine Ahnung woran das liegen könnte?
Das liegt daran, dass in C eine Variablendeklaration im Initialisierungsteil der for-Schleife schlicht und einfach nicht erlaubt ist, zumindest nach dem alten Standard von 1989. Im neuen C-Standard von 1999 ist es erlaubt, aber das kann dein Compiler offenbar nicht, oder du musst es exlipizit einschalten.

Übrigens, "void main" ist auch falsch, in C89, C99 und C++. Es muss "int main" heißen.

Erst mal Danke für die schnelle Antwort. Was mich jetzt aber immer noch verwundert, ist dass in manch anderen Projekten (selbe Solution und selber Projekt-Typ) die Variablendekleration in der for-Schleife reibungslos funktioniert.

Wird wohl so sein. Danke für die Antwort und für die E-Mail-Änderung.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.