What definition of #define cont 32767

  • Thread starter Thread starter woofr_87
  • Start date Start date
  • Tags Tags
    Definition
AI Thread Summary
The discussion centers on the use of the preprocessor directive "#define cont 32767" in C programming, which creates an alias "cont" for the integer value 32767. This means that anywhere "cont" appears in the code, it will be replaced with 32767 during preprocessing, allowing for easier code maintenance. It is suggested that using "const int cont = 32767;" instead would provide better type-checking and safety. The number 32767 may relate to the range of integers in specific contexts, although the full implications depend on the complete code. Overall, the use of #define is a straightforward replacement mechanism in C.
woofr_87
Messages
4
Reaction score
0
Hye.. i got this source code from internet.. i want to ask some quetion..

here is the source code. but not a full code..
PHP:
include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define  cont 32767

typedef struct dnode
	{
		struct dnode *prev;
		int val;
		struct dnode *next;
	}DNODE;

DNODE *rt;

void insert()
 {
	DNODE *temp,*temp1,*temp2;
	int i;
	printf("\nEnter the value of node:");
	scanf("%d",&i);

	temp=(DNODE*)malloc(sizeof(DNODE));
	temp->val=i;
	if(rt==NULL)
what definition/meaning of "#define cont 32767" at line 5...can someone describe to me...thanks..
 
Physics news on Phys.org
It means that "cont" is defined as a kind of alias for the number 32767. So if you would write

int x = cont - 20;

then x would be assigned the value 32767 - 20. Note that the replacement is done by the preprocessor, and is a literal replacement. So by the time your code reaches the compiler it is
int x = 32767 - 20;

In this case, I would recommend making it a proper integer, by using
const int cont = 32767;

Then, whenever you use "cont" in an expression, the compiler can apply type-checking which makes your code safer.
 
In addition to CompuChip's response, the number may come from the range of integers in different situations. I can't confirm since the entire code is not pasted and I cannot see its use (Though as previously stated, with the define it is strictly a replacement), but if you are interested in further readings:

http://en.wikipedia.org/wiki/Integer_(computer_science)
http://home.att.net/~jackklein/c/inttypes.html
 
Last edited by a moderator:

Similar threads

Back
Top