Еще один пример того же, что ребята уже говорят
let langs = ['en', 'fr', 'it'];
let lang = 'en';
setLangStyles(lang);
function setStyles(styles) {
var elementId = '__lang_styles';
var element = document.getElementById(elementId);
if (element) {
element.remove();
}
let style = document.createElement('style');
style.id = elementId;
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = styles;
} else {
style.appendChild(document.createTextNode(styles));
}
document.getElementsByTagName('head')[0].appendChild(style);
}
function setLang(lang) {
setLangStyles(lang);
}
function setLangStyles(lang) {
let styles = langs
.filter(function (l) {
return l != lang;
})
.map(function (l) {
return ':lang('+ l +') { display: none; }';
})
.join(' ');
setStyles(styles);
}
<a href="#" hreflang="it" onclick="setLang('it'); return false">Italiano</a>
<a href="#" hreflang="en" onclick="setLang('en'); return false">English</a>
<a href="#" hreflang="fr" onclick="setLang('fr'); return false">French</a>
<p lang='it'>Ciao a tutti!</p>
<p lang='en'>Hi everyone!</p>
<p lang='fr'>Bon Baguette!</p>
PIC означает независимый от позиции код
и цитирует man gcc
:
Если поддерживается для целевой машины, генерировать позиционно-независимый код, подходящий для динамического связывания и избегающий любых ограничений на размер глобальной таблицы смещения. Эта опция имеет значение для m68k, PowerPC и SPARC. Позиционно-независимый код требует специальной поддержки,
man gcc
говорит:
-fpic Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The 386 has no such limit.) Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent. -fPIC If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k and the SPARC. Position-independent code requires special support, and therefore works only on certain machines.
f
- это префикс gcc для параметров, которые «контролируют используемые соглашения об интерфейсах.
при генерации кода »
PIC
означает« Код, независимый от позиции », это специализация fpic
для m68K и SPARC.
Редактировать: После прочтения страницы 11 документа , на который ссылается 0x6adb015 , и комментария Кориана, я внес несколько изменений:
Этот параметр имеет смысл только для общих библиотек, и вы сообщаете ОС, что используете глобальное смещение Таблица, GOT. Это означает, что все ваши адресные ссылки относятся к GOT, и код может использоваться несколькими процессами.
В противном случае, без этой опции, загрузчику пришлось бы самостоятельно изменять все смещения.
Излишне сказать, мы почти всегда используем -fpic / PIC.