惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Jina AI
Jina AI
小众软件
小众软件
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
美团技术团队
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
博客园 - 司徒正美
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
月光博客
月光博客
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
博客园 - Franky

博客园 - 岁月长河

emacs. verilog mode guide, example Powershell cmdlet 正则表达式篇 之三(BRE和ERE区别)及ELISP ISP architecture considering AHB 总线笔记 English Dictionary site for ODE and OALD vmic environment makefile windows 工具命令 cmd python namespace shell cmd args ROE, ROC IP 链接及常用软件 vim 分屏 and command usages vim autocmd irun vcs option 记录 consonant combination
the diference between include and import
岁月长河 · 2019-03-05 · via 博客园 - 岁月长河

There is an interesting article here regarding the difference between import and `include when it comes to packages. I'm going to attempt to summarise it here.

When you `include a file, it is basically saying take the contents of that file and paste it at the location of the include statement. This is effectively the same behaviour as #include in C/C++.

Great you are thinking, now we have everything in the file, why can't we just use it? Imagine the case though where you are declaring a package in SV. If you `include a file containing a class A into two different packages P and Q, you are basically making a different copy of it in each package, which because of the way SV handles types will be incompatible (you now have one class called P::A and another called Q::A).

This is where import comes in. Unlike `include, the import statement does not copy the definitions being brought in to the file, instead it simply makes them visible. This is similar to the way the using namespace works in C++. Lets say you still `include the class A in package P as before. But now, rather than including A directly in package Q, you import P::A instead, both P and Q now contain the same class P::A instead of having two different ones.

So in summary:

  • `include copies the contents of the file in making a local copy of any classes/types/etc.
  • import doesn't copy but rather makes the existing package declarations visible in the current file

Consider one question, how to address scope visibility of identifier

import content should be compiled once; while include content should not be compiled

import is statement which must be followed by simicolon, include is preprocessor indirective which not need

the class and type which is include at diffrent place, will not be treated as the same object, while import assure the 

coherence