Frage zu Zeigern in C
-
Hallo, ich habe folgenden Cpp Code:
short *samples = new short[total_samples];
Wie wird das in C ausgedrueckt? Denn es liefert mir jedes mal beim Compilieren:
new undeclared (first use in this function)
Hab jetzt leider keine Ahnung wie man das in C ausdruecken kann.
Jemand eine Idee?
-
Statt new hast du in C man: malloc und statt delete hast du man: free.
-
Hiciao schrieb:
short *samples = new short[total_samples];
etwa so:
*short *samples = malloc (total_samples * sizeof(short));
*
oder, wenn du später mal den typ ändern willst:
*short *samples = malloc (total_samples * sizeof(*samples));
*
siehe auch: http://www.c-plusplus.net/forum/viewtopic.php?t=206606
-
Das ging ja schnell
Vielen Dank!