Jump to content

Please Explain this code!

- - - - -

  • Please log in to reply
3 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
Hello All,

I saw this code online and it had the code:

#pragma
#define

I have seen these before, but don't know what they do, for the whole code visit:A cool FileServer by Gerhard Jordaan
Attached File  Client..cpp   4.08K   41 downloads[/ATTACH]

Any explanation would be good.

Thank You.

Attached Files



#2
deskchecked

deskchecked

    Newbie

  • Members
  • PipPip
  • 29 posts
These are preprocessor instructions.

C & C++ provide a preprocessor that your code is filtered through prior to be compiled. This might strip out e.g. comments and unnecessary whitespace, amongst many other things. One of the features of the preprocessor is that you can issue it special instructions.

Of the instructions you're referring to:

#define MY_NAME "Bert"

This tells the preprocessor to replace all occurances of MY_NAME with the string literal "Bert".

#pragma once

Pragma instructions are often compiler-specific (e.g. GCC pragmas might not be available for MSVC and vice versa). This particular pragma is from MSVC, informing the preprocessor that this file should only ever be #included once. There are all sorts of other pragmas available, you'll have to refer to your specific compiler's documentation for more details about what pragmas are supported.

#3
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
Thanks! what about

#if

#endif

They came up too (There is a lot of preprocessor instructions in this).

#4
deskchecked

deskchecked

    Newbie

  • Members
  • PipPip
  • 29 posts
Google for "preprocessor instructions". You'll learn a lot more through educating yourself than being spoon-fed answers. :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users