- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I am trying to use dynamical allocation in fortran with ALLOCATE statement for array of integers. Is ALLOCATE suppose to initialize the array to zero?
Thanks
Oren
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Initialization to 0 of allocated arrays (of integers) is an implementation issue. i.e. do not rely on it. The low level allocation typically calls on the C malloc. Depending on the runtime system you may get it wiped or not wiped. I would suggest you wipe the allocations for your self.
allocate(irray(1234))
irray = 0
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Additional note.
The allocation would not know what initialization value to use. Wiping to 0 is not always desired. Wiping to 0 may be of interest if the cells were to then be subsequently use to accumulate totals. 0's might not be a good choice if the purpose was to provide an indication that a cell was ever used since 0 may be a valid number for use. In this case a better choice would be to initialize to a "magic number" that would seldom, if not never, be used. e.g. initializing to hexidecimal 0xBAADBEEF. Or 0x80000000 (add 0's for size of int) which is arguably -0 because it has the property of (x .eq. -x).
Jim

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page