Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 839 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
#include caching #457101
12/26/15 01:28
12/26/15 01:28
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Today I foudn something new in lite-c. Apparently, multiple #inlcude's to the same file get cached in lite-c:

Example:

print.c file content:
Php Code:
printf("test"); 




main.c file content:
Php Code:
function main() {
  #include "print.c"
  #include "print.c"
} 




"test" will only get printed once in this scnario.

However changing the code to the following:
Php Code:
function main() {
  #include "print.c"
  #include "./print.c"
} 




"test" will get printed twice.

That's all I wanted to say... I know a lot about all the different things lite-c does, but I never knew about this one. Have a nice day!

Re: #include caching [Re: krial057] #457118
12/27/15 10:40
12/27/15 10:40
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I didn't tested it, but I would strongly suggest to not rely on that. Good style is to always use #ifndef/#define/#endif guards around your code. You know what that is?

Re: #include caching [Re: HeelX] #457120
12/27/15 13:40
12/27/15 13:40
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
I know what include guards are. But I wanted to achieve exactly the opposite : include a file twice. Why? For X Macros :

Code:
// File: color_table.h
X(red, "red")
X(green, "green")
X(blue, "blue")

// File: main.c
#include <stdio.h>

#define X(a, b) a,
enum COLOR {
#include "color_table.h"
};
#undef X

#define X(a, b) b,
char *color_name[] = {
#include "color_table.h"
};
#undef X

int main() {
  enum COLOR c = red;
  printf("c=%s\n", color_name[c]);
  return 0;
}


Source :http://www.drdobbs.com/the-new-c-x-macros/184401387

Re: #include caching [Re: krial057] #457121
12/27/15 14:37
12/27/15 14:37
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
That's some weird and inconvenient way to write your code if you ask me...


POTATO-MAN saves the day! - Random
Re: #include caching [Re: Kartoffel] #457122
12/27/15 14:57
12/27/15 14:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
It's not unheard of, and can actually help a lot with decreasing the amounts of code you have to write. It's much easier to use the pre-processor to perform copy and paste than doing it yourself and trying to maintain it.

Personally I find it looks ugly, but I can see it merits as well.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1