Showing posts with label MSDOS. Show all posts
Showing posts with label MSDOS. Show all posts

Precedence of Operators in C++

When writing complex expressions with several operands, we may have some doubts about which operand is
evaluated first and which later. For example, in this expression:
a = 5 + 7 % 2

we may doubt if it really means:
a = 5 + (7 % 2) // with a result of 6, or
a = (5 + 7) % 2 // with a result of 0
The correct answer is the first of the two expressions, with a result of 6. There is an established order with the
priority of each operator, and not only the arithmetic ones (those whose preference come from mathematics) but
for all the operators which can appear in C++. From greatest to lowest priority, the priority order is as follows:
Level Operator Description Grouping
1 :: scope
Left-toright
2
() [] . -> ++ -- dynamic_cast static_cast
reinterpret_cast const_cast typeid postfix
Left-toright
3
++ -- ~ ! sizeof new delete unary (prefix)
Right-toleft
* &
indirection and reference
(pointers)
+ - unary sign operator
4 (type) type casting
Right-toleft
5 .* ->* pointer-to-member
Left-toright
6 * / % multiplicative
Left-toright
7 + - additive
Left-toright
8 << >> shift
Left-toright
9 < > <= >= relational
Left-toright
10 == != equality
Left-toright
11 & bitwise AND
Left-toright
12 ^ bitwise XOR
Left-toright
13 | bitwise OR
Left-toright
14 && logical AND
Left-toright
15 || logical OR
Left-toright
16 ?: conditional
Right-toleft
17 = *= /= %= += -= >>= <<= &= ^= |= assignment
Right-toleft
18 , comma
Left-toright
Grouping defines the precedence order in which operators are evaluated in the case that there are several
operators of the same level in an expression.
All these precedence levels for operators can be manipulated or become more legible by removing possible
ambiguities using parentheses signs ( and ), as in this example:
a = 5 + 7 % 2;


might be written either as:
a = 5 + (7 % 2);
or
a = (5 + 7) % 2;
depending on the operation that we want to perform.
So if you want to write complicated expressions and you are not completely sure of the precedence levels, always
include parentheses. It will also become a code easier to read.

errno.h Defines the system error variable errno and the erro numbers set by system calls. Errors which exist in Unix(tm) but not MSDOS have value -1.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif


/*  Dos Error Codes */

#define EZERO 0 /* Error 0 */
#define EINVFNC 1 /* Invalid function number */
#define ENOFILE 2 /* File not found */
#define ENOPATH 3 /* Path not found */
#define ECONTR 7 /* Memory blocks destroyed */
#define EINVMEM 9 /* Invalid memory block address */
#define EINVENV 10 /* Invalid environment */
#define EINVFMT 11 /* Invalid format */
#define EINVACC 12 /* Invalid access code */
#define EINVDAT 13 /* Invalid data */
#define EINVDRV 15 /* Invalid drive specified */
#define ECURDIR 16 /* Attempt to remove CurDir */
#define ENOTSAM 17 /* Not same device */
#define ENMFILE 18 /* No more files */

#define ENOENT 2 /* No such file or directory */
#define EMFILE 4 /* Too many open files */
#define EACCES 5 /* Permission denied */
#define EBADF 6 /* Bad file number */
#define ENOMEM 8 /* Not enough core */
#define ENODEV 15 /* No such device */
#define EINVAL 19 /* Invalid argument */
#define E2BIG 20 /* Arg list too long */
#define ENOEXEC 21 /* Exec format error */
#define EXDEV 22 /* Cross-device link */
#define EDOM 33 /* Math argument */
#define ERANGE 34 /* Result too large */
#define EEXIST 35 /* File already exists */

#define EFAULT -1 /* Unknown error */
#define EPERM -1 /* UNIX - not MSDOS */
#define ESRCH -1 /* UNIX - not MSDOS */
#define EINTR -1 /* UNIX - not MSDOS */
#define EIO -1 /* UNIX - not MSDOS */
#define ENXIO -1 /* UNIX - not MSDOS */
#define ECHILD -1 /* UNIX - not MSDOS */
#define EAGAIN -1 /* UNIX - not MSDOS */
#define ENOTBLK -1 /* UNIX - not MSDOS */
#define EBUSY -1 /* UNIX - not MSDOS */
#define ENOTDIR -1 /* UNIX - not MSDOS */
#define EISDIR -1 /* UNIX - not MSDOS */
#define ENFILE -1 /* UNIX - not MSDOS */
#define ENOTTY -1 /* UNIX - not MSDOS */
#define ETXTBSY -1 /* UNIX - not MSDOS */
#define EFBIG -1 /* UNIX - not MSDOS */
#define ENOSPC -1 /* UNIX - not MSDOS */
#define ESPIPE -1 /* UNIX - not MSDOS */
#define EROFS -1 /* UNIX - not MSDOS */
#define EMLINK -1 /* UNIX - not MSDOS */
#define EPIPE -1 /* UNIX - not MSDOS */
#define EUCLEAN -1 /* UNIX - not MSDOS */



#define _sys_nerr 35 /* highest defined system error number */

extern int _Cdecl errno;
extern int _Cdecl _doserrno;

dos.h Defines structs, unions, macros, and functions for dealing with MSDOS and the Intel iAPX86 microprocessor family.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#if     !defined(__DOS_DEF_)
#define __DOS_DEF_

/* Variables */
extern int _Cdecl _8087;
extern int _Cdecl _argc;
extern char      **_Cdecl _argv;
extern char      **_Cdecl  environ;
extern int _Cdecl _doserrno;
extern unsigned _Cdecl _heaplen;
extern unsigned char _Cdecl _osmajor;
extern unsigned char _Cdecl _osminor;
extern unsigned _Cdecl _psp;
extern unsigned _Cdecl _stklen;
extern unsigned _Cdecl _version;

#define FA_RDONLY 0x01 /* Read only attribute */
#define FA_HIDDEN 0x02 /* Hidden file */
#define FA_SYSTEM 0x04 /* System file */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
#define FA_ARCH 0x20 /* Archive */

#define NFDS 20 /* Maximum number of fds */

struct fcb {
char fcb_drive; /* 0 = default, 1 = A, 2 = B */
char fcb_name[8]; /* File name */
char fcb_ext[3]; /* File extension */
short fcb_curblk; /* Current block number */
short fcb_recsize; /* Logical record size in bytes */
long fcb_filsize; /* File size in bytes */
short fcb_date; /* Date file was last written */
char fcb_resv[10]; /* Reserved for DOS */
char fcb_currec; /* Current record in block */
long fcb_random; /* Random record number */
};

struct xfcb {
char xfcb_flag; /* Contains 0xff to indicate xfcb */
char xfcb_resv[5]; /* Reserved for DOS */
char xfcb_attr; /* Search attribute */
struct fcb xfcb_fcb; /* The standard fcb */
};

struct country {
int co_date;
char co_curr[5];
char co_thsep[2];
char co_desep[2];
char co_dtsep[2];
char co_tmsep[2];
char co_currstyle;
char co_digits;
char co_time;
long co_case;
char co_dasep[2];
char co_fill[10];
};

struct DOSERROR {
int exterror;
char class;
char action;
char locus;
};

struct dfree {
unsigned df_avail;
unsigned df_total;
unsigned df_bsec;
unsigned df_sclus;
};

struct fatinfo {
char fi_sclus;
char fi_fatid;
int fi_nclus;
int fi_bysec;
};

struct devhdr {
long dh_next; /* Next device pointer */
short dh_attr; /* Attributes */
unsigned short dh_strat; /* Driver strategy routine */
unsigned short dh_inter; /* Driver interrupt routine */
char dh_name[8]; /* Device name */
};

struct time {
unsigned char ti_min; /* Minutes */
unsigned char ti_hour; /* Hours */
unsigned char ti_hund; /* Hundredths of seconds */
unsigned char ti_sec; /* Seconds */
};

struct date {
int da_year; /* Year - 1980 */
char da_day; /* Day of the month */
char da_mon; /* Month (1 = Jan) */
};

struct WORDREGS {
unsigned int ax, bx, cx, dx, si, di, cflag, flags;
};

struct BYTEREGS {
unsigned char al, ah, bl, bh, cl, ch, dl, dh;
};

union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};

struct SREGS {
unsigned int es;
unsigned int cs;
unsigned int ss;
unsigned int ds;
};

struct REGPACK {
unsigned r_ax, r_bx, r_cx, r_dx;
unsigned r_bp, r_si, r_di, r_ds, r_es, r_flags;
};

#define FP_OFF(fp) ((unsigned)(fp))
#define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >> 16))


typedef struct {
char drive; /* do not change */
char pattern [13]; /*  these fields, */
char reserved [7]; /*   Microsoft reserved */
char attrib;
short time;
short date;
long size;
char nameZ [13]; /* result of the search, asciiz */
} dosSearchInfo; /* used with DOS functions 4E, 4F */


int _Cdecl absread (int drive, int nsects, int lsect, void *buffer);
int _Cdecl abswrite(int drive, int nsects, int lsect, void *buffer);
int _Cdecl allocmem(unsigned size, unsigned *segp);
int _Cdecl bdos (int dosfun, unsigned dosdx, unsigned dosal);
int _Cdecl bdosptr (int dosfun, void *argument, unsigned dosal);
struct country *_Cdecl country (int xcode, struct country *cp);
void _Cdecl ctrlbrk (int _Cdecl (*handler)(void));
void _Cdecl delay (unsigned milliseconds);
void _Cdecl disable (void);
int _Cdecl dosexterr (struct DOSERROR *eblkp);
long _Cdecl dostounix (struct date *d, struct time *t);
void          __emit__();
void _Cdecl enable (void);
int _Cdecl freemem (unsigned segx);
int _Cdecl getcbrk (void);
void _Cdecl getdate (struct date *datep);
void _Cdecl getdfree(unsigned char drive, struct dfree *dtable);
void _Cdecl getfat (unsigned char drive, struct fatinfo *dtable);
void _Cdecl getfatd (struct fatinfo *dtable);
unsigned _Cdecl getpsp (void);
int _Cdecl getswitchar (void);
void _Cdecl gettime (struct time *timep);
void interrupt (* _Cdecl getvect(int interruptno)) ();
int _Cdecl getverify (void);
void _Cdecl harderr (int _Cdecl (*handler)());
void _Cdecl hardresume (int axret);
void _Cdecl hardretn(int retn);
int _Cdecl inport (int portid);
unsigned char _Cdecl inportb(int portid);
int _Cdecl int86 (int intno, union REGS *inregs, union REGS *outregs);
int _Cdecl int86x (int intno, union REGS *inregs, union REGS *outregs,
struct SREGS *segregs);
int _Cdecl intdos (union REGS *inregs, union REGS *outregs);
int _Cdecl intdosx (union REGS *inregs, union REGS *outregs,
struct SREGS *segregs);
void _Cdecl intr (int intno, struct REGPACK *preg);
void _Cdecl keep (unsigned char status, unsigned size);
void _Cdecl nosound (void);
void _Cdecl outport (int portid, int value);
void _Cdecl outportb(int portid, unsigned char value);
char *_Cdecl parsfnm (const char *cmdline, struct fcb *fcb, int opt);
int _Cdecl peek (unsigned segment, unsigned offset);
char _Cdecl peekb (unsigned segment, unsigned offset);
void _Cdecl poke (unsigned segment, unsigned offset, int value);
void _Cdecl pokeb (unsigned segment, unsigned offset, char value);
int _Cdecl randbrd (struct fcb *fcb, int rcnt);
int _Cdecl randbwr (struct fcb *fcb, int rcnt);
void _Cdecl segread (struct SREGS *segp);
int _Cdecl setblock(unsigned segx, unsigned newsize);
int _Cdecl setcbrk (int cbrkvalue);
void _Cdecl setdate (struct date *datep);
void _Cdecl setswitchar (char ch);
void _Cdecl settime (struct time *timep);
void _Cdecl setvect (int interruptno, void interrupt (*isr) ());
void _Cdecl setverify (int value);
void _Cdecl sleep (unsigned seconds);
void _Cdecl sound (unsigned frequency);
void _Cdecl unixtodos (long time, struct date *d, struct time *t);
int _Cdecl unlink (const char *path);

/* These are in-line functions.  These prototypes just clean up
  some syntax checks and code generation.
*/

void _Cdecl __cli__ (void);
void _Cdecl __sti__ (void);
unsigned char _Cdecl __inportb__(int portid);
void _Cdecl __outportb__ (int portid, unsigned char value);
void _Cdecl __int__ (int interruptnum);

#define disable() __cli__() /* Clear interrupt flag */
#define enable() __sti__() /* Set interrupt flag */
#define inportb(portid) __inportb__(portid) /* Byte IN instruction */
#define outportb(portid, v) __outportb__(portid,v)/* Byte OUT instruction */
#define geninterrupt(i) __int__(i) /* Interrupt instruction */

/* some other compilers use inp, outp for inportb, outportb */
#define inp(portid) inportb(portid)
#define outp(portid,v) outportb(portid,v)

#if !__STDC__
char far *cdecl getdta(void);
void  cdecl setdta(char far *dta);

#define MK_FP(seg,ofs) ((void far *) \
  (((unsigned long)(seg) << 16) | (unsigned)(ofs)))

#define poke(a,b,c) (*((int  far*)MK_FP((a),(b))) = (int)(c))
#define pokeb(a,b,c) (*((char far*)MK_FP((a),(b))) = (char)(c))
#define peek(a,b) (*((int  far*)MK_FP((a),(b))))
#define peekb(a,b) (*((char far*)MK_FP((a),(b))))
#endif

#endif

conio.h Direct MSDOS console input/output.

Copyright (c) Borland International 1987,1988
All Rights Reserved.
*/
#if !defined(__VIDEO)
#define __VIDEO

#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif

#ifndef __OLDCONIO__

struct text_info {
unsigned char winleft;
unsigned char wintop;
unsigned char winright;
unsigned char winbottom;
unsigned char attribute;
unsigned char normattr;
unsigned char currmode;
unsigned char screenheight;
unsigned char screenwidth;
unsigned char curx;
unsigned char cury;
};

enum text_modes { LASTMODE=-1, BW40=0, C40, BW80, C80, MONO=7 };

#if !defined(__COLORS)
#define __COLORS

enum COLORS {
BLACK, /* dark colors */
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY, /* light colors */
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
};
#endif

#define BLINK 128 /* blink bit */

extern int _Cdecl directvideo;

void _Cdecl clreol (void);
void _Cdecl clrscr (void);
void _Cdecl delline (void);
int _Cdecl gettext (int left, int top, int right, int bottom,
void *destin);
void _Cdecl gettextinfo (struct text_info *r);
void _Cdecl gotoxy (int x, int y);
void _Cdecl highvideo (void);
void _Cdecl insline (void);
void _Cdecl lowvideo (void);
int _Cdecl movetext (int left, int top, int right, int bottom,
int destleft, int desttop);
void _Cdecl normvideo (void);
int _Cdecl puttext (int left, int top, int right, int bottom,
void *source);
void _Cdecl textattr (int newattr);
void _Cdecl textbackground (int newcolor);
void _Cdecl textcolor (int newcolor);
void _Cdecl textmode (int newmode);
int   _Cdecl wherex (void);
int   _Cdecl wherey (void);
void _Cdecl window (int left, int top, int right, int bottom);
#endif

char *_Cdecl cgets (char *str);
int   _Cdecl cprintf (const char *format, ...);
int _Cdecl cputs (const char *str);
int _Cdecl cscanf (const char *format, ...);
int _Cdecl getch (void);
int _Cdecl getche (void);
char *_Cdecl getpass (const char *prompt);
int _Cdecl kbhit (void);
int _Cdecl putch (int c);
int _Cdecl ungetch (int ch);

#endif