Initialize dynamic allocated data before main get error?

From: Tony Johansson (johansson.andersson_at_telia.com)
Date: 04/29/04


Date: Thu, 29 Apr 2004 08:58:38 GMT

Hello Experts!!

Here an easy question. If I initialize the dynamic allocated q global which
means before main I get a lot of compilation error.
I just want to know why I can't do that.

I can assign an integer to tal and I can assign the string "this is a test"
to the name field before the main without any problem.
If I instead move the initialize of q to the main part it works.

int tal = 5;
char namn[] = "this is a test";

int *q = new int[5];
q[0] = 0;
q[1] = 1;
q[2] = 2;
q[3] = 3;
q[4] = 4;

int main()
{
    return 0;
}

//Tony



Relevant Pages

  • Re: Record type flushing
    ... If you try to assign a new value to a string field in that ... reference, so the compiler's code tries to release that reference before ... The Initialize procedure can be used to solve that problem. ... If you're using the shell's memory manager, ...
    (alt.comp.lang.borland-delphi)
  • Re: Lets make it backwards compatible :D
    ... > Incorrect use of Initialize. ... it is a string. ... The pointer storage would point to the null terminator. ... Storage now holds a string reference. ...
    (alt.comp.lang.borland-delphi)
  • Re: Is there a difference between passing "" and passing Nothing to a Windows API ?
    ... string to string variables" lazy because it prevents the developer from ... It's to always initialize it to something when I declare it. ... Anyhow, please describe "potential problems?" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: recursive function problem
    ... def show_params ... This allows you to keep internal knowledge inside, ... You still have an issue in that you only initialize the variable params_str ... and you cannot then concatenate additional string to it. ...
    (comp.lang.ruby)
  • Re: Access types as parameters
    ... Initialize is doing is to set up some fields in Button: ... Most GTK subprograms do need access values; the same is true of any ... package Window is ... function Name_Dispatch return String; ...
    (comp.lang.ada)