Talk:Comparison of Object Pascal and C

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing  
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
 ???  This article has not yet received a rating on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 
WikiProject C/C++  
WikiProject icon This article is within the scope of WikiProject C/C++, a collaborative effort to improve the coverage of C/C++ on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
 ???  This article has not yet received a rating on the quality scale.
 ???  This article has not yet received a rating on the importance scale.
 

The string example is plain wrong ...[edit]

1. "as is a Keyword. This code will not compile. 2. The concatenation of a AnsiString with a Shortstring into a Shortstring will be silently truncated to 255 bytes if the resulting length exceeds the 255 char limit. I suggest the original author adapts the example accordingly.

Fixed and implemented[edit]

Next time, feel free to edit yourself, it's a wiki after all.

Leledumbo (talk) 02:57, 31 July 2014 (UTC)

A mistake...[edit]

quotation
Despite of its treatment as pointer, not all pointer style constructs could be used to array. For example, this code would compile fine but would cause access violation when executed:

void func(int *a) {
// RUNTIME ERROR! a is allocated statically
a = (int*) malloc(sizeof(int) * 10);
}

int main() {
int a[5];
func(a);
}
end of quotation

No, it is not a run time error. Remember that C/C++ passes parameters by value. So, "a" within "func" is a local copy of the pointer.
a = (int*) malloc(sizeof(int) * 10);
allocates the new memory, and assigns the memory address to "a", which is a local variable (as a byval parameter).

It is a memory leak, because the memory is allocated, and not freed. However, by itself, it will not cause an access violation.

If you were to declare "a" as const:
void func(int * const a) {
then you would get a compiler error. 107.33.42.66 (talk) 06:20, 15 August 2013 (UTC)

Right, please edit accordingly[edit]

I'd like to explain that things like this could happen (I had it some time ago, but I don't remember the exact code), but it looks like I've given a wrong example. Anyway, declaring the parameter as const doesn't give me compile error on gcc 4.8.1.

Leledumbo (talk) 02:58, 31 July 2014 (UTC)