What definition of #define cont 32767

  • Thread starter Thread starter woofr_87
  • Start date Start date
  • Tags Tags
    Definition
Click For Summary
SUMMARY

The discussion centers on the use of the preprocessor directive #define cont 32767 in C programming. This directive creates an alias for the integer value 32767, allowing for easier code readability and maintenance. A recommendation is made to replace the macro with a constant integer declaration, const int cont = 32767;, to enhance type safety and enable compiler type-checking. The implications of using macros versus constants in terms of code safety and clarity are emphasized.

PREREQUISITES
  • Understanding of C programming syntax and structure
  • Familiarity with preprocessor directives in C
  • Knowledge of memory management in C, particularly with malloc
  • Basic understanding of data structures, specifically linked lists
NEXT STEPS
  • Research the differences between #define and const in C programming
  • Learn about the C preprocessor and its directives
  • Explore memory management techniques in C, focusing on dynamic allocation
  • Study linked list implementation and manipulation in C
USEFUL FOR

C programmers, software developers, and computer science students looking to deepen their understanding of preprocessor directives and memory management 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

  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
10K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K