Re: Problem bei for Anweisung



Hallo,

Sebastian Waschik <sebastian.waschik@xxxxxx> wrote:
Jason Mayer <JacK_McRiDER@xxxxxxx> writes:
Tremos schrub:
for ( zaehler ; zaehler < 499; feld[zaehler++]=WERT)

"Warning: statement with no effect"

Schreib lieber
for(; zaehler <= 500; feld[zaehler++] = WERT)

Entweder zaehler<500 oder zaehler<=499, sonst greifst du schreibend auf
das (nicht existierende) 500ste Feldelement zu.

Das gleiche tut uebrigens auch ein
memset(feld, WERT, 500);

memset kann man nur verwenden, wenn man ein char-Feld hat. Im Falle
von
int feld [500];
ist der memset-Aufruf aber nicht gleichwertig zur for-Schleife.

Korrekt.

Ein Fehler des ursprünglichen Programmes war übrigends, dass "feld"
nicht initialisiert wurde, bevor es verwendet wurde.

Nein, der Fehler des urspruenglichen Programms war, dass die
Abbruchbedingung falsch war.

Mit "int feld [500] = {};" würde es initalisiert werden.

Es wird auch so mit 0 initialisiert, siehe C99-Standard Abschnitt 6.7.8
("Initialization") Punkt 10. unter "Constraints":
----------------------
10 If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or
unsigned) zero;
— if it is an aggregate, every member is initialized (recursively)
according to these rules;
— if it is a union, the first named member is initialized
(recursively) according to these rules.
----------------------

Tschuess,
Juergen Ilse (juergen@xxxxxxxxxxxxxxxxxxxx)
--
Ein Domainname (auch wenn er Teil einer Mailadresse ist) ist nur ein Name,
nicht mehr und nicht weniger ...
.



Relevant Pages

  • Re: Translation-Time Type Information
    ... there are three points of undefined behaviour in the ... point within the same array object. ... functions return the 'value' member of the pointed-to-union, ... pointer is equal to the alignment requirement for that function ...
    (comp.lang.c)
  • Re: Casting of pointer to member functions
    ... cast it back before any usage. ... The example above will compile only if /ymg compiler switch ... the bits that pointer is ... calling a member function through such pointer is ...
    (microsoft.public.vc.language)
  • Re: Class members, pointers or not?
    ... > Is it best to declare class member objects as pointers or not pointers? ... using pointer members (and reference members) ...
    (comp.lang.cpp)
  • Re: request for member in something not a structure or union
    ... to be either a structure or a pointer to structure. ... accessing the same member via a pointer to the structure as two ... int csr; ... The compiler did not bother to see whether p->next or t.next ...
    (comp.lang.c)
  • Re: Forward references and recursion
    ... It needs not only the name, but it need to know the declaration, to calculate ... A workaround, is to change the member as the pointer to the list, ... Probably you needs just a outside lists of plain data classes, ...
    (microsoft.public.vc.stl)