Showing posts with label Language. Show all posts
Showing posts with label Language. Show all posts

Sunday, April 22, 2012

Programming Language Generations



HELLO GUYS IF YOU ARE INTERESTED TO KNOW ABOUT GENERATION OF PROGRAMMING LANGUAGES THAN MUST READ THIS ARTICLE!!!!!!!!!!!!!!!


In the computer industry, these abbreviations are widely used to represent major steps or "generations" in the evolution of programming languages.

1GL or first-generation language was (and still is) machine language or the level of instructions and data that the processor is actually given to work on (which in conventional computers is a string of 0s and 1s).

2GL or second-generation language is assembler (sometimes called "assembly") language.An assembler converts the assembler language statements into machine language.


3GL or third-generation language is a "high-level" programming language, such as PL/I, C, orJava. A compiler converts the statements of a specific high-level programming language into machine language. (In the case of Java, the output is called bytecode, which is converted into appropriate machine language by a Java virtual machine that runs as part of an operating system platform.) A 3GL language requires a considerable amount of programming knowledge.


4GL or fourth-generation language is designed to be closer to natural language than a 3GL language. Languages for accessing databases are often described as 4GLs


5GL or fifth-generation language is programming that uses a visual or graphical development interface to create source language that is usually compiled with a 3GL or 4GL language compiler. Microsoft, Borland, IBM, and other companies make 5GL visual programming products for developing applications in Java.

             THANK YOU FRIENDS..........

Tuesday, March 13, 2012

Dangling Pointer?????????

pointers that do not point to a valid object of the appropriate type. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, as silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (*NIX) or general protection faults (Windows). 


Let us understand through the following code snippet:-

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define BLOCKSIZE 20;
int main()
{
char *ptr;
ptr=(char *)malloc(BLOCKSIZE);
if(ptr!=NULL)
strcpy(ptr,"mohin khan");
printf("content=%s",ptr);
printf("naddress=%u",ptr);
free(ptr);
printf("nAfter free");
printf("ncontent=%s",ptr);
printf("naddress=%u",ptr);
}
output of the above code
content=mohin khan
address=134520840      //(just a example)
After free
content=
address=134520840     //same as the previous address

so we can conclude from the above code that
after free() also i keeps the address but content is deallocated.so now it is not pointing to any valid memory location.Hence ptr is now dangling pointer which probably having a address but not pointing to any valid memory location.
so it is good practice to assign NULL after freeing the allocated memory as below

ptr=NULL;

in this way dangling problem will be solved. 




  <-------------------Thanking You----------------------> 

Tuesday, March 06, 2012

What is the difference between goto and longjmp() and setjmp()?????????





A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions  implement a  nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmp in your program.

A goto statement simply bypasses code in your program and jumps to a predefined position. To use the goto statement, you give it a labeled position to jump to. This predefined position must be within the same function. You cannot implement gotos between functions.

 Here is an example of a goto statement:

void bad_programmers_function(void)

{

int x;

printf(“Excuse me while I count to 5000...\n”);

x = 1;

while (1)

{

printf(“%d\n”, x);

if (x == 5000)

goto all_done;

else

x = x + 1;

}

all_done:

printf(“Whew! That wasn’t so bad, was it?\n”);

}
This example could have been written much better, avoiding the use of  a goto statement
Here is an example of an improved implementation:

void better_function(void)

{

int x;

printf(“Excuse me while I count to 5000...\n”);

for (x=1; x<=5000; x++)

printf(“%d\n”, x);

printf(“Whew! That wasn’t so bad, was it?\n”);

}

As previously mentioned, the longjmp() and setjmp() functions implement a nonlocal goto. When your program calls setjmp(), the current state of your program is saved in a structure of type jmp_buf. Later, your program can call the  longjmp() function to restore the program’s state as it was when you called setjmp(). Unlike the  goto statement, the longjmp() and setjmp() functions do not need to be implemented in the same function. However, there is a major drawback to using these functions: your program, when restored  to its previously saved state, will lose its references to any dynamically allocated memory between the longjmp() and the setjmp(). This means you will waste memory for every malloc() or calloc() you have implemented between your  ongjmp() and setjmp(), and your program will be horribly inefficient. It is highly recommended that you avoid using functions such as  longjmp() and setjmp() because they, like the goto statement, are quite often an indication of poor programming practice.
Here is an example of the longjmp() and setjmp() functions:


#include <stdio.h>

#include <setjmp.h>

jmp_buf saved_state;

void main(void);

void call_longjmp(void);

void main(void)

{

int ret_code;

printf(“The current state of the program is being saved...\n”);

ret_code = setjmp(saved_state);

if (ret_code == 1)

{

printf(“The longjmp function has been called.\n”);

printf(“The program’s previous state has been restored.\n”);

exit(0);

}
printf(“I am about to call longjmp and\n”);

printf(“return to the previous program state...\n”);

call_longjmp();

}

void call_longjmp(void)

{

longjmp(saved_state, 1);

}


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Thanking You!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Popular Posts